Skip to content

Commit e9003c1

Browse files
committed
feat(s3-deployment): support securityGroups in BucketDeploymentProps
1 parent 6ea230c commit e9003c1

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

packages/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ export interface BucketDeploymentProps {
282282
* @default true
283283
*/
284284
readonly outputObjectKeys?: boolean;
285+
286+
/**
287+
* The list of security groups to associate with the lambda handlers network interfaces.
288+
*
289+
* Only used if 'vpc' is supplied.
290+
*
291+
* @default undefined - If the function is placed within a VPC and a security group is
292+
* not specified, either by this or securityGroup prop, a dedicated security
293+
* group will be created for this function.
294+
*/
295+
readonly securityGroups?: ec2.ISecurityGroup[];
285296
}
286297

287298
/**
@@ -366,6 +377,7 @@ export class BucketDeployment extends Construct {
366377
ephemeralStorageSize: props.ephemeralStorageSize,
367378
vpc: props.vpc,
368379
vpcSubnets: props.vpcSubnets,
380+
securityGroups: props.securityGroups ? props.securityGroups : undefined,
369381
filesystem: accessPoint ? lambda.FileSystem.fromEfsAccessPoint(
370382
accessPoint,
371383
mountPath,

packages/aws-cdk-lib/aws-s3-deployment/test/bucket-deployment.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,36 @@ test('deployment allows vpc and subnets to be implicitly supplied to lambda', ()
11231123
});
11241124
});
11251125

1126+
test('deployment allows security groups to be explicitly supplied to lambda', () => {
1127+
// GIVEN
1128+
const stack = new cdk.Stack();
1129+
const bucket = new s3.Bucket(stack, 'Dest');
1130+
const vpc = new ec2.Vpc(stack, 'SomeVpc', {});
1131+
const securityGroup = new ec2.SecurityGroup(stack, 'SomeSecurityGroup', { vpc });
1132+
1133+
// WHEN
1134+
new s3deploy.BucketDeployment(stack, 'DeployWithVpc1', {
1135+
sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
1136+
destinationBucket: bucket,
1137+
vpc,
1138+
securityGroups: [securityGroup],
1139+
});
1140+
1141+
// THEN
1142+
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
1143+
VpcConfig: Match.objectLike({
1144+
SecurityGroupIds: Match.arrayWith([
1145+
{
1146+
'Fn::GetAtt': Match.arrayWith([
1147+
Match.stringLikeRegexp('SomeSecurityGroup'), // Matches dynamically generated SG name
1148+
'GroupId',
1149+
]),
1150+
},
1151+
]),
1152+
}),
1153+
});
1154+
});
1155+
11261156
test('s3 deployment bucket is identical to destination bucket', () => {
11271157
// GIVEN
11281158
const stack = new cdk.Stack();

packages/aws-cdk/lib/cli/parse-command-line-arguments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ export function parseCommandLineArguments(args: Array<string>): any {
733733
type: 'string',
734734
alias: 'l',
735735
desc: 'The language to be used for the new project (default can be configured in ~/.cdk.json)',
736-
choices: ['csharp', 'fsharp', 'go', 'java', 'javascript', 'python', 'typescript'],
736+
choices: ['app.iml', 'csharp', 'fsharp', 'go', 'java', 'javascript', 'python', 'typescript'],
737737
})
738738
.option('list', {
739739
default: undefined,

0 commit comments

Comments
 (0)