Skip to content

Instantly share code, notes, and snippets.

@thanhtungka91
Last active May 16, 2020 08:48
Show Gist options
  • Save thanhtungka91/643d6e1e84eccde72232641ed192df22 to your computer and use it in GitHub Desktop.
Save thanhtungka91/643d6e1e84eccde72232641ed192df22 to your computer and use it in GitHub Desktop.
  1. aws s3 ls bucket //(note always check '/' the end of the bucket)
  2. show object to get the key of object 3.list objets to get key
    aws s3api list-objects --bucket bucketname
  3. public aws s3api put-object-acl --bucket $bucketname --key $key --acl public-read

Reference documents https://aws.amazon.com/premiumsupport/knowledge-center/read-access-objects-s3-bucket/

  1. cors
<CORSConfiguration>
 <CORSRule>
   <AllowedOrigin>http://www.example1.com</AllowedOrigin>

   <AllowedMethod>PUT</AllowedMethod>
   <AllowedMethod>POST</AllowedMethod>
   <AllowedMethod>DELETE</AllowedMethod>

   <AllowedHeader>*</AllowedHeader>
 </CORSRule>
 <CORSRule>
   <AllowedOrigin>http://www.example2.com</AllowedOrigin>

   <AllowedMethod>PUT</AllowedMethod>
   <AllowedMethod>POST</AllowedMethod>
   <AllowedMethod>DELETE</AllowedMethod>

   <AllowedHeader>*</AllowedHeader>
 </CORSRule>
 <CORSRule>
   <AllowedOrigin>*</AllowedOrigin>
   <AllowedMethod>GET</AllowedMethod>
 </CORSRule>
</CORSConfiguration>

https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html

  1. anable by cli
aws s3api put-bucket-cors --bucket MyBucket --cors-configuration file://cors.json

cors.json:
{
  "CORSRules": [
    {
      "AllowedOrigins": ["http://www.example.com"],
      "AllowedHeaders": ["*"],
      "AllowedMethods": ["PUT", "POST", "DELETE"],
      "MaxAgeSeconds": 3000,
      "ExposeHeaders": ["x-amz-server-side-encryption"]
    },
    {
      "AllowedOrigins": ["*"],
      "AllowedHeaders": ["Authorization"],
      "AllowedMethods": ["GET"],
      "MaxAgeSeconds": 3000
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment