Created
          January 29, 2017 10:46 
        
      - 
      
- 
        Save inokappa/a41c1ccf150012be02d20c2ba95c1ba8 to your computer and use it in GitHub Desktop. 
    既存のディストリビューションをコピーして新しい CloudFront ディストリビューションを作るシェルスクリプトのサンプル
  
        
  
    
      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/bash | |
| _AWS_PROFILE=${AWS_PROFILE} | |
| _SOURCE_DIST_ID=${SOURCE_DIST_ID} | |
| _UNIX_TIME=$(date +%s) | |
| _ORIGIN_TAEGET=${1} | |
| _ORIGIN_TAEGET_DOMAIN=${2} | |
| _SOURCE_DIST_SETTING=$(aws --profile ${_AWS_PROFILE} cloudfront\ | |
| get-distribution \ | |
| --id ${_SOURCE_DIST_ID} \ | |
| | jq -r ".Distribution \ | |
| | .DistributionConfig.CallerReference = \"${_UNIX_TIME}\" \ | |
| | .DistributionConfig.DefaultCacheBehavior.TargetOriginId = \"${_ORIGIN_TAEGET}\" \ | |
| | .DistributionConfig.Origins.Items[0].Id = \"${_ORIGIN_TAEGET}\" \ | |
| | .DistributionConfig.Origins.Items[0].DomainName = \"${_ORIGIN_TAEGET_DOMAIN}\" \ | |
| | del(.ARN, .Status, .DomainName, .InProgressInvalidationBatches, .ActiveTrustedSigners, .LastModifiedTime, .Id, .DistributionConfig.Aliases, .DistributionConfig.ViewerCertificate)" \ | |
| ) | |
| echo "-------------------------------------------------------------------------------------------" | |
| echo ${_SOURCE_DIST_SETTING} | jq . | |
| echo "-------------------------------------------------------------------------------------------" | |
| echo -n "実行するコマンド: aws --profile ${_AWS_PROFILE} cloudfront create-distribution --cli-input-json "${_SOURCE_DIST_SETTING}"" | |
| echo "" | |
| echo -n "実行しますか?[y/n]> " | |
| read INPUT | |
| case "${INPUT}" in | |
| "y" | "Y" ) echo "実行中..." && \ | |
| aws --profile ${_AWS_PROFILE} cloudfront create-distribution --cli-input-json "${_SOURCE_DIST_SETTING}" ;; | |
| * ) echo "Canceled." ; exit 0 ;; | |
| esac | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment