AWS S3 Essentials

AWS Logo

AWS S3 Essentials
Simple Storage Service
Object Storage
Objects can range from 0 bytes to 5TB

AWS Logo

Make Bucket

aws s3 mb s3://newuniquebucketname

Remove Bucket

aws s3 rb s3://BUCKETNAME

If you get
remove_bucket failed: s3://BUCKETNAME An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete i
s not empty

aws s3 rb s3://BUCKETNAME --force

List Bucket

aws s3 ls

List Bucket Objects

aws s3 ls s3://BUCKET_NAME

aws s3api list-objects --bucket <YOUR_BUCKET_NAME>
aws s3api list-objects --bucket <YOUR_BUCKET_NAME> --page-size 5
aws s3api list-objects --bucket <YOUR_BUCKET_NAME> --max-items 1

Upload

aws s3 cp myfile.txt s3://BUCKET_NAME
aws s3api put-object --bucket <BUCKET_NAME> --key data.csv --body data.csv

CloudFormation

Most basic template

MyS3Bucket:
    Type: AWS::S3::Bucket

Bucket Policy

Sample for a public static website

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::BUCKETNAME/*"
        }
    ]
}

Pre Sign URL

Will last for 1 hour by defualt

aws s3 presign s3://BUCKETNAME/myfile.txt
aws s3 presign s3://BUCKETNAME/myfile.txt --expires-in 300
  • https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html
  • https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/index.html
  • https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-s3.html
  • https://aws.amazon.com/s3/storage-classes/
  • https://aws.amazon.com/premiumsupport/knowledge-center/s3-bucket-owner-full-control-acl/
  • https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-transition-general-considerations.html
  • https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_mfa_enable_virtual.html
  • https://docs.aws.amazon.com/AmazonS3/latest/userguide/MultiFactorAuthenticationDelete.html
  • https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html