Crear web estática en S3 con CLI
Crear Web estática en S3 con AWS CLI
Pasos
Previo
Configurar AWS CLI
- Conecta con el
Learner Lab
- Copia las
credentials
de tu usuario de IAM en~/.aws/credentials
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
Mostramos un ejemplo, puedes subir tu web estática
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
Última modificación September 30, 2023: website s3 (9c3f86f)