DEV Community

Agik Setiawan
Agik Setiawan

Posted on

Setup CORS and Policy in Object Storage like s3 or anoter Object Storage with s3cmd

In your ~/.s3cfg

[default]
access_key = ACCESS_KEY
host_base = ENDPOINT
host_bucket = YOUR_BUCKET_NAME.ENDPOINT
secret_key = SECRET_KEY
Enter fullscreen mode Exit fullscreen mode

or you can configure with command s3cmd --configure for new or reconfig default s3cmd

  • Set Policy create file policy.json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject",
                "s3:GetObjectVersion"
            ],
            "Resource": "arn:aws:s3:::BUCKET_NAME/*"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

you can customize policy.json according to you needs.

open terminal

s3cmd setpolicy policy.json s3://BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode
  • Set CORS create file cors.xml
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Enter fullscreen mode Exit fullscreen mode

Open terminal

s3cmd setcors cors.xml s3://BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

Top comments (0)