Skip to content

Commit 0ae5557

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

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,42 @@ test('deployment allows vpc and subnets to be implicitly supplied to lambda', ()
11231123
});
11241124
});
11251125

1126+
test('deployment allows security groups to be implicitly supplied to lambda', () => {
1127+
// GIVEN
1128+
const stack = new cdk.Stack();
1129+
const bucket = new s3.Bucket(stack, 'Dest');
1130+
const vpc: ec2.IVpc = new ec2.Vpc(stack, 'SomeVpc', {});
1131+
const securityGroups: ec2.SecurityGroup = new ec2.SecurityGroup(stack, 'SomeSecurityGroup', {
1132+
vpc: vpc,
1133+
});
1134+
1135+
// WHEN
1136+
new s3deploy.BucketDeployment(stack, 'DeployWithVpc1', {
1137+
sources: [s3deploy.Source.asset(path.join(__dirname, 'my-website'))],
1138+
destinationBucket: bucket,
1139+
vpc,
1140+
securityGroups: [securityGroups],
1141+
});
1142+
1143+
// THEN
1144+
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
1145+
VpcConfig: {
1146+
SecurityGroupIds: [
1147+
{
1148+
'Fn::GetAtt': [
1149+
'SomeSecurityGroup',
1150+
'GroupId',
1151+
],
1152+
},
1153+
],
1154+
SubnetIds: Match.arrayWith([
1155+
{ Ref: 'SomeVpc1PrivateSubnet1SubnetCBA5DD76' },
1156+
{ Ref: 'SomeVpc1PrivateSubnet2SubnetD4B3A566' },
1157+
]),
1158+
},
1159+
});
1160+
});
1161+
11261162
test('s3 deployment bucket is identical to destination bucket', () => {
11271163
// GIVEN
11281164
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)