I have the following code:
logger.info(
"Invalidating cache...",
extra={
"bucket": event.bucket_name,
"distribution_id": DISTRIBUTION_ID,
"index_paths": index_paths,
},
)
cloudfront.create_invalidation(
DistributionId=DISTRIBUTION_ID,
InvalidationBatch={
"Paths": {"Quantity": len(index_paths), "Items": index_paths},
"CallerReference": context.aws_request_id,
},
)
I have run it many times successfully with different args but this time I got the error:
An error occurred (InvalidArgument) when calling the CreateInvalidation operation: Your request contains one or more invalid invalidation paths.
The preceding log line showed:
"index_paths": [
"index.html",
"Movies/index.html"
],
These paths both exist (checked bucket in aws console).
One of them will have been newly created, and I suspect this may be the problem? i.e. the file had not been requested and cached yet?
It's a pain for me to rewrite the code so that it can identify creates vs updates and only invalidate the updates. Also even with updates how am I to know if it was requested and cached yet?
Can anyone confirm or point to docs suggesting cause of this error?
Paths should start with /
.
Use index_paths
like.
"index_paths": [
"/index.html",
"/Movies/index.html"
],