I'm new to jq and trying to extract key and value from selected fields.
{
"StackEvents": [
{
"StackId": "arn:aws:cloudformation:us-east-1:1234567890123:stack/jenkinscf-s3/f64657b0-cb0a-11ed-848f-0a093f43c24f",
"EventId": "06263740-cb0b-11ed-86ee-0e3b4b6ffec3",
"StackName": "jenkinscf-s3",
"LogicalResourceId": "jenkinscf-s3",
"PhysicalResourceId": "arn:aws:cloudformation:us-east-1:1234567890123:stack/jenkinscf-s3/f64657b0-cb0a-11ed-848f-0a093f43c24f",
"ResourceType": "AWS::CloudFormation::Stack",
"Timestamp": "2023-03-25T12:46:12.647000+00:00",
"ResourceStatus": "CREATE_COMPLETE"
},
{
"StackId": "arn:aws:cloudformation:us-east-1:1234567890123:stack/jenkinscf-s3/f64657b0-cb0a-11ed-848f-0a093f43c24f",
"EventId": "S3Bucket-CREATE_COMPLETE-2023-03-25T12:46:11.127Z",
"StackName": "jenkinscf-s3",
"LogicalResourceId": "S3Bucket",
"PhysicalResourceId": "jenkinscf-s3-s3bucket-tmh6orxmeegs",
"ResourceType": "AWS::S3::Bucket",
"Timestamp": "2023-03-25T12:46:11.127000+00:00",
"ResourceStatus": "CREATE_COMPLETE",
"ResourceProperties": "{}"
},
{
"StackId": "arn:aws:cloudformation:us-east-1:1234567890123:stack/jenkinscf-s3/f64657b0-cb0a-11ed-848f-0a093f43c24f",
"EventId": "S3Bucket-CREATE_IN_PROGRESS-2023-03-25T12:45:50.261Z",
"StackName": "jenkinscf-s3",
"LogicalResourceId": "S3Bucket",
"PhysicalResourceId": "jenkinscf-s3-s3bucket-tmh6orxmeegs",
"ResourceType": "AWS::S3::Bucket",
"Timestamp": "2023-03-25T12:45:50.261000+00:00",
"ResourceStatus": "CREATE_IN_PROGRESS",
"ResourceStatusReason": "Resource creation Initiated",
"ResourceProperties": "{}"
},
{
"StackId": "arn:aws:cloudformation:us-east-1:1234567890123:stack/jenkinscf-s3/f64657b0-cb0a-11ed-848f-0a093f43c24f",
"EventId": "S3Bucket-CREATE_IN_PROGRESS-2023-03-25T12:45:49.665Z",
"StackName": "jenkinscf-s3",
"LogicalResourceId": "S3Bucket",
"PhysicalResourceId": "",
"ResourceType": "AWS::S3::Bucket",
"Timestamp": "2023-03-25T12:45:49.665000+00:00",
"ResourceStatus": "CREATE_IN_PROGRESS",
"ResourceProperties": "{}"
},
{
"StackId": "arn:aws:cloudformation:us-east-1:1234567890123:stack/jenkinscf-s3/f64657b0-cb0a-11ed-848f-0a093f43c24f",
"EventId": "f64b87d0-cb0a-11ed-848f-0a093f43c24f",
"StackName": "jenkinscf-s3",
"LogicalResourceId": "jenkinscf-s3",
"PhysicalResourceId": "arn:aws:cloudformation:us-east-1:1234567890123:stack/jenkinscf-s3/f64657b0-cb0a-11ed-848f-0a093f43c24f",
"ResourceType": "AWS::CloudFormation::Stack",
"Timestamp": "2023-03-25T12:45:46.136000+00:00",
"ResourceStatus": "CREATE_IN_PROGRESS",
"ResourceStatusReason": "User Initiated"
}
]
}
Expected output
"LogicalResourceId": "jenkinscf-s3"
"ResourceStatus": "CREATE_COMPLETE"
The solutions I have tried only gets me the key or the value but not both.
.StackEvents | .[] | .LogicalResourceId, .ResourceStatus
"jenkinscf-s3"
"CREATE_COMPLETE"
"S3Bucket"
"CREATE_COMPLETE"
"S3Bucket"
"CREATE_IN_PROGRESS"
"S3Bucket"
"CREATE_IN_PROGRESS"
"jenkinscf-s3"
"CREATE_IN_PROGRESS"
.StackEvents[] | keys
[
"EventId",
"LogicalResourceId",
"PhysicalResourceId",
"ResourceStatus",
"ResourceType",
"StackId",
"StackName",
"Timestamp"
]
My end goal is to use this in a bash script. The script will detect drifts in the stack and output the differences. It currently runs and only outputs the values, so anyone unfamiliar with the script will get easily confused just by looking at the keys themselves.
StackEvents
array with five elements. Each element is an object with a certain set of keys and their values. What do you want to get out from these five objects and what is the criteria for extracting that data?Timestamp
value).