Last active
November 9, 2019 19:36
-
-
Save ajorg/2c49c9dafe726f6eea026627575dea75 to your computer and use it in GitHub Desktop.
Deploys a certificate renewed by certbot-s3front
This file contains 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
# Copyright (c) Andrew Jorgensen. All rights reserved. | |
# SPDX-License-Identifier: MIT-0 | |
# Requires jq and assumes AWS CLI --output json | |
DISTRIBUTION_ID="<YOUR DISTRIBUTION ID>" | |
DISTRIBUTION_CONFIG="$( | |
aws cloudfront get-distribution-config \ | |
--id "${DISTRIBUTION_ID}" \ | |
| jq -c .)" | |
# FRAGILE! Picks a certificate created today (UTC). | |
CERTIFICATE_ID="$( | |
aws iam list-server-certificates \ | |
| jq -r ".ServerCertificateMetadataList[] | |
| select(.UploadDate | startswith(\"$(date --utc +%F)T\")) | |
| .ServerCertificateId")" | |
aws cloudfront update-distribution \ | |
--id "${DISTRIBUTION_ID}" \ | |
--if-match "$(jq -r '.ETag' <<<"${DISTRIBUTION_CONFIG}")" \ | |
--distribution-config "$( | |
jq -c --arg certificate "${CERTIFICATE_ID}" \ | |
'.DistributionConfig | |
| .ViewerCertificate.IAMCertificateId = $certificate | |
| .ViewerCertificate.Certificate = $certificate' \ | |
<<<"${DISTRIBUTION_CONFIG}")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment