MCPcopy Create free account
hub / github.com/aws-samples/personalization-apis / lambda_handler

Function lambda_handler

src/sync_cache_settings_function/main.py:305–330  ·  view source on GitHub ↗
(event, _)

Source from the content-addressed store, hash-verified

303@logger.inject_lambda_context
304@tracer.capture_lambda_handler
305def lambda_handler(event, _):
306 # The "event" is the configuration (passed as input to step function)
307 logger.info(event)
308
309 # Check the autoProvision flag on all cacheControl objects to make sure auto-provisioning is not disabled.
310 jsonpath_expr = parse('$..cacheControl[*].autoProvision')
311 auto_provision = [match.value for match in jsonpath_expr.find(event)]
312 logger.debug('cacheControl.autoProvision values: %s', auto_provision)
313 if len(auto_provision) == 0 or not False in auto_provision:
314 origin_request_headers, cache_headers = determine_required_cloudfront_headers(event)
315
316 if REST_API_ID and REST_API_STAGE:
317 update_apigw_rest_stage_caching(event, cache_headers)
318 pass
319 else:
320 # This can be the case when a dedicated CloudFront distribution is being used for caching.
321 logger.info('REST API ID and/or stage name are not specified; skipping REST API sync')
322
323 if CLOUD_FRONT_CACHE_POLICY_ID and CLOUD_FRONT_ORIGIN_REQUEST_POLICY_ID:
324 update_cloudfront_origin_request_policy(origin_request_headers)
325 update_cloudfront_cache_policy(event, cache_headers)
326 else:
327 # This can be the case when an API Gateway Edge endpoint type is being used (API Gateway manages its own CloudFront distribution)
328 logger.info('CloudFront cache policy ID and/or origin request policy ID are not specified; skipping')
329 else:
330 logger.info('Auto provisioning of caching related resources is disabled for at least one cacheControl configuration; skipping CloudFront/API Gateway sync')

Callers

nothing calls this directly

Tested by

no test coverage detected