Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lambda): add ipv6AllowedForDualStack for lambda function #28059

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/aws-cdk-lib/aws-lambda/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ export interface FunctionOptions extends EventInvokeConfigOptions {
*/
readonly allowAllOutbound?: boolean;

/**
* Indicates whether IPv6 protocols will be allowed for dual stack subnets.
*
* @default false
*/
readonly ipv6AllowedForDualStack?: boolean;

/**
* Enabled DLQ. If `deadLetterQueue` is undefined,
* an SQS queue with default options will be defined for your Function.
Expand Down Expand Up @@ -1370,6 +1377,9 @@ Environment variables can be marked for removal when used in Lambda@Edge by sett
if (props.vpcSubnets) {
throw new Error('Cannot configure \'vpcSubnets\' without configuring a VPC');
}
if (props.ipv6AllowedForDualStack) {
throw new Error('Cannot configure \'ipv6AllowedForDualStack\' without configuring a VPC');
}
return undefined;
}

Expand Down Expand Up @@ -1412,6 +1422,9 @@ Environment variables can be marked for removal when used in Lambda@Edge by sett
'If you are aware of this limitation and would still like to place the function in a public subnet, set `allowPublicSubnet` to true');
}
}

const ipv6AllowedForDualStack = props.ipv6AllowedForDualStack ?? false;

this.node.addDependency(selectedSubnets.internetConnectivityEstablished);

// List can't be empty here, if we got this far you intended to put your Lambda
Expand All @@ -1421,6 +1434,7 @@ Environment variables can be marked for removal when used in Lambda@Edge by sett
return {
subnetIds: selectedSubnets.subnetIds,
securityGroupIds: securityGroups.map(sg => sg.securityGroupId),
ipv6AllowedForDualStack,
};
}

Expand Down
40 changes: 39 additions & 1 deletion packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,48 @@ describe('lambda + vpc', () => {
code: new lambda.InlineCode('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_LATEST,
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE },
vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
});
}).toThrow('Cannot configure \'vpcSubnets\' without configuring a VPC');
});

test('specifying ipv6AllowedForDualStack without a vpc throws an Error', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
expect(() => new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_LATEST,
ipv6AllowedForDualStack: true,
})).toThrow(/Cannot configure 'ipv6AllowedForDualStack' without configuring a VPC/);
});

test('can specify ipv6AllowedForDualStack for Lambda', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc', {
maxAzs: 3,
natGateways: 1,
});

// WHEN
new lambda.Function(stack, 'MyLambda', {
vpc,
code: new lambda.InlineCode('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_LATEST,
ipv6AllowedForDualStack: true,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {
VpcConfig: {
Ipv6AllowedForDualStack: true,
},
});
});
});

class SomethingConnectable implements ec2.IConnectable {
Expand Down
Loading