File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed
Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 7777 run : npx vitest --retry 1 test/cdk-basic.test.ts
7878 - name : Test - observability mode
7979 run : OBSERVABLE_MODE=true npx vitest --retry 1 test/cdk-basic.test.ts
80+ - name : Deploy YAML version
81+ run : npm run deploy-yaml
82+ working-directory : test/cdk-basic
83+ - name : Test YAML
84+ run : npx vitest --retry 1 test/cdk-basic.test.ts
8085
8186 test-cdk-esm :
8287 runs-on : ubuntu-latest
Original file line number Diff line number Diff line change 66import { AwsCredentials } from './awsCredentials.js' ;
77import { AwsConfiguration } from './types/awsConfiguration.js' ;
88import { Logger } from './logger.js' ;
9+ import * as yaml from 'yaml' ;
910
1011let cloudFormationClient : CloudFormationClient ;
1112
@@ -30,7 +31,17 @@ async function getCloudFormationStackTemplate(
3031 throw new Error ( `No template found for stack ${ stackName } ` ) ;
3132 }
3233
33- const cfTemplate = JSON . parse ( response . TemplateBody ) ;
34+ let cfTemplate : any ;
35+ try {
36+ cfTemplate = JSON . parse ( response . TemplateBody ) ;
37+ } catch ( parseError : any ) {
38+ if ( parseError . message . includes ( 'is not valid JSON' ) ) {
39+ // If the template is not JSON, try parsing it as YAML
40+ cfTemplate = yaml . parse ( response . TemplateBody ) ;
41+ } else {
42+ throw parseError ;
43+ }
44+ }
3445 return cfTemplate ;
3546 } catch ( error : any ) {
3647 if ( error . name === 'ValidationError' ) {
Original file line number Diff line number Diff line change 1+ # This script is used to deploy the CDK stack using a YAML template.
2+ npx cdk synth -c environment=test CdkbasicStack > CdkbasicStack.yaml
3+ # Add a dummy resource to the template to force a change in the stack
4+ awk '
5+ /^Resources:/ && !injected {
6+ print
7+ print " DummyForceResource:"
8+ print " Type: AWS::CloudFormation::WaitConditionHandle"
9+ print " Properties: {}"
10+ injected=1
11+ next
12+ }
13+ { print }
14+ ' CdkbasicStack.yaml > template.patched.yaml && mv template.patched.yaml CdkbasicStack.yaml
15+ aws cloudformation deploy --template-file CdkbasicStack.yaml --stack-name test-lld-cdk-basic --capabilities CAPABILITY_NAMED_IAM
Original file line number Diff line number Diff line change 77 "scripts" : {
88 "deploy" : " cdk deploy --all -c environment=test --require-approval never --outputs-file cdk-outputs.json" ,
99 "build" : " cdk synth -c environment=test" ,
10+ "deploy-yaml" : " bash deploy-yaml.sh" ,
1011 "destroy" : " cdk destroy --all -c environment=test --force"
1112 },
1213 "devDependencies" : {
You can’t perform that action at this time.
0 commit comments