Skip to content

Instantly share code, notes, and snippets.

@lmorillas
Last active September 30, 2023 20:02
Show Gist options
  • Save lmorillas/778b11635c812ab8815d6ffee82373db to your computer and use it in GitHub Desktop.
Save lmorillas/778b11635c812ab8815d6ffee82373db to your computer and use it in GitHub Desktop.

Crear un bucket S3 y configurarlo como sitio web estático con AWS CLI

Crear Bucket S3

bucket_name="miwebs3-nombre-bucket-unico"

aws s3api create-bucket --bucket "${bucket_name}"

Configuramos el bucket para que sea publico

aws s3api put-public-access-block --bucket "${bucket_name}" --public-access-block-configuration "BlockPublicPolicy=false"

aws s3api put-bucket-policy --bucket "${bucket_name}" --policy '{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::'"${bucket_name}"'/*"
 
            ]
        }
    ]
}'

Subimos un fichero html

echo "<html><center><h1>My Static Website on S3</h1></center></html>" > index.html

aws s3 cp index.html s3://"${bucket_name}"

Configuramos el bucket para que sea un sitio web

aws s3 website s3://"${bucket_name}" --index-document index.html

Comprobamos que funciona

curl http://"${bucket_name}".s3-website.us-east-1.amazonaws.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment