aws
aws is a command tool that lets you manage and interact with AWS resources.
S3
Sync folder contents with S3 bucket
aws s3 sync public/ s3://mybucket --dryrun
aws s3 sync public/ s3://mybucket
List buckets
aws s3 ls
Make bucket. Buckets are created in region specified in user’s config file by default. Region can be specified as a parameter.
aws s3 mb s3://mybucket
aws s3 mb s3://mybucket --region us-west-1
Make bucket as static website and use curl to access it. Note that you need to also define a public access bucket policy for curl to work.
aws s3 website s3://www.foo.com/ --index-document index.html --region us-east-1
curl -I www.foo.com.s3-website.us-east-1.amazonaws.com
Troubleshooting
Can’t access objects in S3 website
In addition to creating a bucket marked as a static website, you have to define an access policy that enables objects in that bucket to be read by public (non-authenticated) users. You can define the policy in the AWS S3 UI under Permissions -> Bucket Policy. Here is a sample one.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::www.foo.com/*"
}
]
}
Glossary
- bucket
- Top level container for S3 objects. Users can have many buckets. Buckets
contain many objects. Bucket names must be unique within an AWS region.
Buckets can be set as static websites. When that happens, objects in the bucket will be available at the url
http://<bucket-name>.s3-website.<region>.amazonaws.com
. For ex. the bucketfoo.com
in theus-west-1
region would be available athttp://foo.com.s3-website.us-west-1.amazonaws.com