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개 답변
1
수락된 답변

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
전문가
답변함 일 년 전
  • 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
전문가
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠