Skip to content

Commit 2b4ef20

Browse files
authored
HookStack: Allow multiple instances (#31)
Just some internal cleanup to support multiple `HookStack` tests without running into this error: ```shell Asset is already associated with another stack 'aws-codedeploy-hooks'. Create a new Code instance for every stack. ```
1 parent 26bc06e commit 2b4ef20

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

.changeset/plenty-steaks-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-infra': patch
3+
---
4+
5+
HookStack: Allow multiple instances

packages/infra/src/constructs/lambda.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path';
22

33
import { Duration, aws_lambda } from 'aws-cdk-lib';
44

5-
export const LAMBDA_HOOK_PROPS: aws_lambda.FunctionProps = {
5+
export const createLambdaHookProps = (): aws_lambda.FunctionProps => ({
66
code: aws_lambda.Code.fromAsset(
77
path.join(__dirname, '..', 'assets', 'handlers'),
88
),
@@ -19,4 +19,4 @@ export const LAMBDA_HOOK_PROPS: aws_lambda.FunctionProps = {
1919
runtime: aws_lambda.Runtime.NODEJS_20_X,
2020

2121
timeout: Duration.seconds(300),
22-
};
22+
});

packages/infra/src/constructs/stack.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ it('returns expected CloudFormation stack', () => {
2424

2525
expect(JSON.parse(json)).toMatchSnapshot();
2626
});
27+
28+
it('supports a custom ID', () => {
29+
const app = new App();
30+
31+
const stack = new HookStack(app, 'MyStack');
32+
33+
const template = assertions.Template.fromStack(stack);
34+
35+
template.resourceCountIs('AWS::Lambda::Function', 1);
36+
});

packages/infra/src/constructs/stack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Stack, aws_iam, aws_lambda } from 'aws-cdk-lib';
22
import type { Construct } from 'constructs';
33

4-
import { LAMBDA_HOOK_PROPS } from './lambda';
4+
import { createLambdaHookProps } from './lambda';
55

66
export type HookStackProps = Record<string, never>;
77

@@ -17,7 +17,7 @@ export class HookStack extends Stack {
1717
this,
1818
'BeforeAllowTrafficHook',
1919
{
20-
...LAMBDA_HOOK_PROPS,
20+
...createLambdaHookProps(),
2121
description: 'BeforeAllowTraffic hook deployed outside of a VPC',
2222
functionName: 'aws-codedeploy-hook-BeforeAllowTraffic',
2323
vpc: undefined,

0 commit comments

Comments
 (0)