Skip to content

Commit

Permalink
Merge pull request #246 from RockefellerArchiveCenter/development
Browse files Browse the repository at this point in the history
Invalidates Cloudfront cache after build
  • Loading branch information
helrond authored Nov 19, 2024
2 parents 4ab9292 + 9b17882 commit 5ce75e7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def run(self, audience, branch, deploy=True):
site.build()
if deploy:
site.upload(audience, branch)
site.invalidate_cache(audience, branch)
else:
logging.info(
f'Skipping upload to S3 for {audience} {branch} site.')
Expand Down Expand Up @@ -153,6 +154,27 @@ def upload(self, audience, branch):
'').lstrip('/'),
f),
ExtraArgs={'ContentType': mtype if mtype else 'application/json'})

def invalidate_cache(self, audience, branch):
distribution_id = decrypt_env_variable(
f'{branch.upper()}_{audience.upper()}_DISTRIBUTION')
cloudfront = boto3.client(
'cloudfront',
region_name=decrypt_env_variable('REGION_NAME'),
aws_access_key_id=decrypt_env_variable('ACCESS_KEY'),
aws_secret_access_key=decrypt_env_variable('SECRET_KEY'))
cloudfront.create_invalidation(
DistributionId=distribution_id,
InvalidationBatch={
'Paths': {
'Quantity': 1,
'Items': [
'/*',
]
},
'CallerReference': datetime.now().timestamp().replace('.', '')
}
)


def main(event=None, context=None):
Expand Down

0 comments on commit 5ce75e7

Please sign in to comment.