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 Antworten
1
Akzeptierte Antwort

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
EXPERTE
beantwortet vor einem Jahr
  • 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
EXPERTE
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen