步骤函数的AWS CLI查询和过滤



我想使用AWS CLI按名称和通配符字符串获取步骤函数ARN,或者按步骤函数名称获取步骤函数ARN

下面是一个例子:

aws stepfunctions list-state-machines --region us-east-1

I got this:

{
"stateMachines": [
{
"stateMachineArn": "arn:aws:states:us-east-1:012345678912:stateMachine:firstStepFunc",
"name": "firstStepFunc",
"type": "STANDARD",
"creationDate": "2022-12-01T14:43:09.577000+01:00"
}
]
}

我试了这个:

aws stepfunctions list-state-machines --query 'stateMachines[*].stateMachineArn' --region us-east-1 --output text

并得到预期结果:

arn:aws:states:us-east-1:012345678912:stateMachine:firstStepFunc

但是如果阶跃函数大于1,它将不起作用

我需要这样的东西,但我不知道如何以适当的方式编写查询:

aws stepfunctions list-state-machines --query 'stateMachines[*].stateMachineArn[?stateMachineArn==`*`]' --region us-east-1
aws stepfunctions list-state-machines --query 'stateMachines[*].stateMachineArn[?name==`*`]' --region us-east-1

提前感谢!

您可以使用contains函数,例如:

aws stepfunctions list-state-machines --query 'stateMachines[?contains(name,`dev`)]|[*].stateMachineArn' --region us-east-1 --output text

上面的表达式返回名称中包含dev关键字的所有步进函数的ARN。如果您只想获得一个(例如,第一个),您可以执行以下操作:

aws stepfunctions list-state-machines --query 'stateMachines[?contains(name,`dev`)]|[0].stateMachineArn' --region us-east-1 --output text