Using JQ to delete blocks from json CloudFormation templates
I'm using jq (on bash) to delete key blocks from json templates. I'm currently deleting 50% of what I want, by using the "Type" element from CloudFormation templates :
jq '(del(.Resources | .[] | select(.Type=="AWS::CodePipeline::Pipeline")))' $fileName > newTemplate1.json
I Would also need to delete every resources that contains "cdkpipelinePipeline", before the Type block :
"developcdkpipelinePipelineRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "codepipeline.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"Tags": [
{
"Key": "Application",
"Value": "develop"
}
]
},
"DependsOn": [
"AuroraNestedStackAuroraNestedStackResource"
],
"Metadata": {
"aws:cdk:path": "develop-cicd-stack/develop-cdkpipeline/Pipeline/Role/Resource"
}
}
}, ... ``
Do you have any clue on how to achieve that ? I Basically want every blocks with a key that contains "cdkpipelinePipeline" to be removed from my template.
Thank you already
How about jq 'delpaths([paths | select(contains(["cdkpipelinePipeline"]))])' ?
Works just fine, take you very much :)