从创建失效中存储或检索标识符

问题描述 投票:0回答:2

我正在尝试创建一个失效请求作为

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

很快就想听它完成使用

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

如何获取失效请求生成的ID?

amazon-cloudfront
2个回答
4
投票
# 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


0
投票

对于那些在 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
© www.soinside.com 2019 - 2024. All rights reserved.