amazon-cloudfront

Store or retrieve identifier from create-invalidation


I am trying to create an invalidation request as

aws cloudfront create-invalidation --distribution-id  XXXXXX --paths '/*'

and soon want to listen for it to complete using

aws cloudfront wait invalidation-completed --id <<NEED ID HERE>> --distribution-id XXXXXX && callback()

How to get the ID generated from invalidation request?


Solution

  • # Store the output of the create-invalidation command in a variable
    invalidation_output=$(aws cloudfront create-invalidation --distribution-id XXXXXX --paths '/*')
    
    # Extract the Invalidation ID using jq (make sure you have jq installed)
    invalidation_id=$(echo $invalidation_output | jq -r '.Invalidation.Id')
    

    Ref :https://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-invalidation.html#examples