-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Multiple stacks in a single app dependent stacks 1`] = ` | ||
{ | ||
"Resources": { | ||
"BarA6AB415C": { | ||
"DependsOn": [ | ||
"BarServiceRole3E5F94C9", | ||
], | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { | ||
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", | ||
}, | ||
"S3Key": "7ecc77636deefb31954ea2e6aadf6d2c361a2943535a678d65f46a8de5e1f503.zip", | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"BarServiceRole3E5F94C9", | ||
"Arn", | ||
], | ||
}, | ||
"Runtime": "nodejs20.x", | ||
}, | ||
"Type": "AWS::Lambda::Function", | ||
}, | ||
"BarServiceRole3E5F94C9": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition", | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", | ||
], | ||
], | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Multiple stacks in a single app dependent stacks 2`] = ` | ||
{ | ||
"Resources": { | ||
"BarA6AB415C": { | ||
"DependsOn": [ | ||
"BarServiceRole3E5F94C9", | ||
], | ||
"Properties": { | ||
"Code": { | ||
"S3Bucket": { | ||
"Fn::Sub": "cdk-hnb659fds-assets-\${AWS::AccountId}-\${AWS::Region}", | ||
}, | ||
"S3Key": "7ecc77636deefb31954ea2e6aadf6d2c361a2943535a678d65f46a8de5e1f503.zip", | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"BarServiceRole3E5F94C9", | ||
"Arn", | ||
], | ||
}, | ||
"Runtime": "nodejs20.x", | ||
}, | ||
"Type": "AWS::Lambda::Function", | ||
}, | ||
"BarServiceRole3E5F94C9": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition", | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", | ||
], | ||
], | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Multiple stacks in a single app one stack referencing the other 1`] = ` | ||
{ | ||
"Outputs": { | ||
"ExportsOutputFnGetAttFooDFE0DD70Arn2A3BEF77": { | ||
"Export": { | ||
"Name": "S3:ExportsOutputFnGetAttFooDFE0DD70Arn2A3BEF77", | ||
}, | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"FooDFE0DD70", | ||
"Arn", | ||
], | ||
}, | ||
}, | ||
}, | ||
"Resources": { | ||
"FooDFE0DD70": { | ||
"DeletionPolicy": "Retain", | ||
"Type": "AWS::S3::Bucket", | ||
"UpdateReplacePolicy": "Retain", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`Multiple stacks in a single app one stack referencing the other 2`] = ` | ||
{ | ||
"Outputs": { | ||
"ExportsOutputFnGetAttFooDFE0DD70Arn2A3BEF77": { | ||
"Export": { | ||
"Name": "S3:ExportsOutputFnGetAttFooDFE0DD70Arn2A3BEF77", | ||
}, | ||
"Value": { | ||
"Fn::GetAtt": [ | ||
"FooDFE0DD70", | ||
"Arn", | ||
], | ||
}, | ||
}, | ||
}, | ||
"Resources": { | ||
"FooDFE0DD70": { | ||
"DeletionPolicy": "Retain", | ||
"Type": "AWS::S3::Bucket", | ||
"UpdateReplacePolicy": "Retain", | ||
}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Stack, App } from "aws-cdk-lib"; | ||
import { Bucket } from "aws-cdk-lib/aws-s3"; | ||
import { Function, Code, Runtime } from "aws-cdk-lib/aws-lambda"; | ||
import "../index"; | ||
import path from "path"; | ||
|
||
describe("Multiple stacks in a single app", () => { | ||
test("dependent stacks", () => { | ||
const app = new App(); | ||
const s3Stack = new Stack(app, "S3"); | ||
new Bucket(s3Stack, "Foo"); | ||
|
||
const lambdaStack = new Stack(app, "Lambda"); | ||
new Function(lambdaStack, "Bar", { | ||
code: Code.fromAsset(path.join(__dirname, "fixtures", "lambda")), | ||
handler: "index.handler", | ||
runtime: Runtime.NODEJS_20_X, | ||
}); | ||
|
||
expect(s3Stack).toMatchCdkSnapshot(); | ||
expect(lambdaStack).toMatchCdkSnapshot(); | ||
}); | ||
|
||
test("one stack referencing the other", () => { | ||
const app = new App(); | ||
const s3Stack = new Stack(app, "S3"); | ||
const bucket = new Bucket(s3Stack, "Foo"); | ||
|
||
const lambdaStack = new Stack(app, "Lambda"); | ||
new Function(lambdaStack, "Bar", { | ||
code: Code.fromAsset(path.join(__dirname, "fixtures", "lambda")), | ||
handler: "index.handler", | ||
runtime: Runtime.NODEJS_20_X, | ||
environment: { | ||
bucket: bucket.bucketArn, | ||
}, | ||
}); | ||
|
||
expect(s3Stack).toMatchCdkSnapshot(); | ||
expect(lambdaStack).toMatchCdkSnapshot(); | ||
}); | ||
}); |