Scilla
Scilla

Reputation: 385

Query AWS Stack Resource AWS CLI

I want to Qyery AWS Stack Resource Aws Cl so I can get the PhysicalResourceId.

To describe the stacks and query it is resented in this post.

describe the stacks

If I want to describe my stack resource I use this command

aws cloudformation describe-stack-resource --stack-name banana --logical-resource-id orange

Is there a way to get the PhysicalResourceId from the output. which is a Json format?

{
    "StackResourceDetail": {
        "StackName": "strawbery",
        "StackId": "arn:aws:cloudformation:us-west-2:0000000000:stack/orange/pinaple",
        "LogicalResourceId": "PotatoInstance",
        "PhysicalResourceId": "i-00000000001",
        "ResourceType": "AWS::EC2::Instance",
        "LastUpdatedTimestamp": "orange",
        "ResourceStatus": "CREATE_COMPLETE",
        "Metadata": "{}",
        "DriftInformation": {
            "StackResourceDriftStatus": "NOT_CHECKED"
        }
    }
}

I think there would be a way if I'd use awk, but I don't know how to use it.

awk

Update:

I need to use awk as it will be done in a pipeline and the pipeline doesn't have jq installed.

Upvotes: 2

Views: 937

Answers (1)

Balu Vyamajala
Balu Vyamajala

Reputation: 10363

We can use AWS --query --query StackResourceDetail.PhysicalResourceId

aws cloudformation describe-stack-resource --stack-name banana --logical-resource-id orange --query StackResourceDetail.PhysicalResourceId

Upvotes: 2

Related Questions