我正在尝试创建一个失效请求作为
aws cloudfront create-invalidation --distribution-id XXXXXX --paths '/*'
很快就想听它完成使用
aws cloudfront wait invalidation-completed --id <<NEED ID HERE>> --distribution-id XXXXXX && callback()
如何获取失效请求生成的ID?
# 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')
参考:https://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-invalidation.html#examples
对于那些在 2024 年寻找答案并且不想依赖 jq 的人,以下内容对我的批次有用:
setlocal enabledelayedexpansion
::Cloudfront Invalidation
SET "invalidationPaths=aws cloudfront create-invalidation --distribution-id XXXXXXXX --paths "/*" --output json --query Invalidation.Id"
for /f "delims=" %%i in ('%invalidationPaths%') do set invalidation_id=%%i
echo Created invalidation !invalidation_id!
aws cloudfront wait invalidation-completed --id !invalidation_id! --distribution-id XXXXXXXX
echo Invalidation Complete