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 77
77
run : npx vitest --retry 1 test/cdk-basic.test.ts
78
78
- name : Test - observability mode
79
79
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
80
85
81
86
test-cdk-esm :
82
87
runs-on : ubuntu-latest
Original file line number Diff line number Diff line change 6
6
import { AwsCredentials } from './awsCredentials.js' ;
7
7
import { AwsConfiguration } from './types/awsConfiguration.js' ;
8
8
import { Logger } from './logger.js' ;
9
+ import * as yaml from 'yaml' ;
9
10
10
11
let cloudFormationClient : CloudFormationClient ;
11
12
@@ -30,7 +31,17 @@ async function getCloudFormationStackTemplate(
30
31
throw new Error ( `No template found for stack ${ stackName } ` ) ;
31
32
}
32
33
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
+ }
34
45
return cfTemplate ;
35
46
} catch ( error : any ) {
36
47
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 7
7
"scripts" : {
8
8
"deploy" : " cdk deploy --all -c environment=test --require-approval never --outputs-file cdk-outputs.json" ,
9
9
"build" : " cdk synth -c environment=test" ,
10
+ "deploy-yaml" : " bash deploy-yaml.sh" ,
10
11
"destroy" : " cdk destroy --all -c environment=test --force"
11
12
},
12
13
"devDependencies" : {
You can’t perform that action at this time.
0 commit comments