S3 cheatsheetEdit
Policy:
Block all public access
(precondition for enabling public access)
- Bucket policy
JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnablePublicAccess",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::ps-serverless-test-hosting/*"
}
]
}
Adding metadata manually
- Object
- Edit Metadata
Type: System defined -> Key -> Cache-Control x-age=31536000, public
local cache the static content for 1 year (works best when bundle has hash in the name)
Adding metadata with aws CLI
# Configuring Cache Control for JS/CSs Files (1 Year) (1 week 604800)
aws s3 cp \ s3://ps-serverless-hosting/ s3://ps-serverless-hosting/ \
--exclude '*' \
--include '*.css' --include '*.js' \
--cache-control 'max-age=31104000, public' \
--recursive \
--metadata-directive REPLACE --acl public-read
Block all public access
(precondition for enabling public access)JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnablePublicAccess",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::ps-serverless-test-hosting/*"
}
]
}
- Object
- Edit Metadata
Type: System defined -> Key -> Cache-Control x-age=31536000, public
local cache the static content for 1 year (works best when bundle has hash in the name)
Adding metadata with aws CLI
# Configuring Cache Control for JS/CSs Files (1 Year) (1 week 604800)
aws s3 cp \ s3://ps-serverless-hosting/ s3://ps-serverless-hosting/ \
--exclude '*' \
--include '*.css' --include '*.js' \
--cache-control 'max-age=31104000, public' \
--recursive \
--metadata-directive REPLACE --acl public-read
# Configuring Cache Control for JS/CSs Files (1 Year) (1 week 604800)
aws s3 cp \ s3://ps-serverless-hosting/ s3://ps-serverless-hosting/ \
--exclude '*' \
--include '*.css' --include '*.js' \
--cache-control 'max-age=31104000, public' \
--recursive \
--metadata-directive REPLACE --acl public-read