Last active
March 30, 2017 20:20
-
-
Save david-sanabria/a26a33fe2f85dc0f40d6496536e83d84 to your computer and use it in GitHub Desktop.
AWS CLI - Test for S3 Bucket Existence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [[ $(aws s3api list-buckets --query 'Buckets[?starts_with(Name,`my-bucket`)].[Name]' --output text) = 'my-bucket' ]]; then | |
echo "You're a genius. Now do something useful"; | |
fi | |
## Alternate Syntax | |
if [[ $(aws s3api list-buckets --query 'Buckets[?Name == `my-bucket`].[Name]' --output text) = 'my-bucket' ]]; then | |
echo "You're a specific genius. Now do something useful"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a very simple example of a very powerful capability of Amazon's command line utility. Not only can I create stuff, I but i can use JMESPath queries to validate that I created it. This is useful for doing conditional evaluation (test if its there before using it).