Last active
          April 18, 2022 04:31 
        
      - 
      
- 
        Save petrabarus/dfa7e7639bbc630c502b8e932f8da4fe to your computer and use it in GitHub Desktop. 
    Invalidate CloudFront Distribution and Wait
  
        
  
    
      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
    
  
  
    
  | #!/usr/bin/env bash | |
| # Requirements | |
| # - AWS | |
| # - jq | |
| # Variables | |
| PROFILE= | |
| DISTRIBUTION_ID= | |
| PATHS="/*" | |
| # Check required dependencies | |
| aws --version && jq --version | |
| # Invalidate | |
| echo "Invalidating $DISTRIBUTION_ID" | |
| OUTPUT=$(aws --profile $PROFILE cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths $PATH) | |
| echo "Invalidation Created." | |
| echo $OUTPUT | jq -r | |
| INVALIDATION_ID=$(echo $OUTPUT | jq -r '.Invalidation.Id') | |
| echo "Invalidation ID: $INVALIDATION_ID" | |
| # Wait until complete | |
| echo "Waiting..." | |
| aws --profile $PROFILE cloudfront wait invalidation-completed --distribution-id $DISTRIBUTION_ID --id $INVALIDATION_ID | |
| echo "Completed!" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment