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 Answers
1
Accepted Answer

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
EXPERT
answered a year ago
  • 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
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions