Skip to content

Commit ec06f48

Browse files
authored
fix(eks): cluster cannot be created in opt-in regions (#20009)
The default STS endpoint of the v2 JS SDK is the global endpoint, which does not work in opt-in regions: it has to be the regional endpoint. Fix this by setting a global environment variable for the custom resource Lambdas. Fixes #13748, fixes #15579. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d38a9e4 commit ec06f48

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/@aws-cdk/aws-eks/lib/cluster-resource-provider.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export class ClusterResourceProvider extends NestedStack {
8080
code: lambda.Code.fromAsset(HANDLER_DIR),
8181
description: 'onEvent handler for EKS cluster resource provider',
8282
runtime: HANDLER_RUNTIME,
83-
environment: props.environment,
83+
environment: {
84+
AWS_STS_REGIONAL_ENDPOINTS: 'regional',
85+
...props.environment,
86+
},
8487
handler: 'index.onEvent',
8588
timeout: Duration.minutes(1),
8689
vpc: props.subnets ? props.vpc : undefined,
@@ -94,7 +97,10 @@ export class ClusterResourceProvider extends NestedStack {
9497
code: lambda.Code.fromAsset(HANDLER_DIR),
9598
description: 'isComplete handler for EKS cluster resource provider',
9699
runtime: HANDLER_RUNTIME,
97-
environment: props.environment,
100+
environment: {
101+
AWS_STS_REGIONAL_ENDPOINTS: 'regional',
102+
...props.environment,
103+
},
98104
handler: 'index.isComplete',
99105
timeout: Duration.minutes(1),
100106
vpc: props.subnets ? props.vpc : undefined,

packages/@aws-cdk/aws-eks/test/cluster.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,26 @@ describe('cluster', () => {
709709
},
710710
},
711711
});
712+
});
713+
714+
test('cluster handler gets created with STS regional endpoint configuration', () => {
715+
// This is necessary to make aws-sdk-jsv2 work in opt-in regions
716+
717+
// GIVEN
718+
const { stack, vpc } = testFixture();
712719

720+
// WHEN
721+
new eks.Cluster(stack, 'Cluster', { vpc, defaultCapacity: 0, version: CLUSTER_VERSION, prune: false });
713722

723+
// THEN
724+
const nested = stack.node.tryFindChild('@aws-cdk/aws-eks.ClusterResourceProvider') as cdk.NestedStack;
725+
Template.fromStack(nested).hasResourceProperties('AWS::Lambda::Function', {
726+
Environment: {
727+
Variables: {
728+
AWS_STS_REGIONAL_ENDPOINTS: 'regional',
729+
},
730+
},
731+
});
714732
});
715733

716734
test('if "vpc" is not specified, vpc with default configuration will be created', () => {

0 commit comments

Comments
 (0)