how to get s3 website url using aws cli ?

0

How can I use AWS CLI to retrieve the URL for my S3 static site? I have tried using the command

aws s3api get-bucket-website --bucket my-site --profile my-site-profile --output text

but it does not return any result. I need to obtain the S3 URL for my site, such as "http://my-site-dev.s3-website-us-west-2.amazonaws.com".

aws cli version

aws --version
aws-cli/2.7.15 Python/3.9.11 Linux/5.19.0-38-generic exe/x86_64.ubuntu.22 prompt/off

2 Respostas
1
Resposta aceita

Hi, I would use

aws s3api get-bucket-location --bucket <BUCKET_NAME> --output text ====> <REGION>

and then use the <REGION> info to build the website string, which is pretty standard:

http://<BUCKET_NAME>.s3-website.<REGION>.amazonaws.com

Hope it helps ;)

profile picture
ESPECIALISTA
respondido há um ano
  • aws cli should give the full url, just saying

  • I agree with you. It is unfortunate that it doesn’t support that

0

The existing answer is good but there is an (ugly but workable) alternative:

aws s3 presign s3://BUCKETNAME/a | awk '{split($1,a,"/"); print a[3]}'

Note that this doesn't make a call on the network - it's a completely local operation.

profile pictureAWS
ESPECIALISTA
respondido há um ano

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas