Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
既存のディストリビューションをコピーして新しい CloudFront ディストリビューションを作るシェルスクリプトのサンプル
#!/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