Skip to content

Commit 706dc89

Browse files
authored
fix(apigatewayv2): does not work in non-aws partition (#25284)
We hard `aws` partitions hardcoded in certain strings. Adds an eslint rule to prevent the same from happening again in the future. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 6f7c4b5 commit 706dc89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+345
-123
lines changed

packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/bootstrapping.integtest.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @aws-cdk/no-literal-partition */
12
import * as fs from 'fs';
23
import * as path from 'path';
34
import * as yaml from 'yaml';

packages/@aws-cdk/aws-apigatewayv2-alpha/lib/http/integration.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IRole } from 'aws-cdk-lib/aws-iam';
2-
import { Resource } from 'aws-cdk-lib';
2+
import { Aws, Resource } from 'aws-cdk-lib';
33
import { Construct } from 'constructs';
44
import { IHttpApi } from './api';
55
import { HttpMethod, IHttpRoute } from './route';
@@ -103,7 +103,7 @@ export abstract class IntegrationCredentials {
103103

104104
/** Use the calling user's identity to call the integration */
105105
public static useCallerIdentity(): IntegrationCredentials {
106-
return { credentialsArn: 'arn:aws:iam::*:user/*' };
106+
return { credentialsArn: `arn:${Aws.PARTITION}:iam::*:user/*` };
107107
}
108108

109109
/**

packages/@aws-cdk/aws-apigatewayv2-alpha/lib/http/route.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as iam from 'aws-cdk-lib/aws-iam';
2-
import { Resource } from 'aws-cdk-lib';
2+
import { Aws, Resource } from 'aws-cdk-lib';
33
import { Construct } from 'constructs';
44
import { IHttpApi } from './api';
55
import { HttpRouteAuthorizerConfig, IHttpRouteAuthorizer } from './authorizer';
@@ -236,7 +236,7 @@ export class HttpRoute extends Resource implements IHttpRoute {
236236
// path variable and all that follows with a wildcard.
237237
const iamPath = path.replace(/\{.*?\}.*/, '*');
238238

239-
return `arn:aws:execute-api:${this.env.region}:${this.env.account}:${this.httpApi.apiId}/${stage}/${iamHttpMethod}${iamPath}`;
239+
return `arn:${Aws.PARTITION}:execute-api:${this.env.region}:${this.env.account}:${this.httpApi.apiId}/${stage}/${iamHttpMethod}${iamPath}`;
240240
}
241241

242242
public grantInvoke(grantee: iam.IGrantable, options: GrantInvokeOptions = {}): iam.Grant {

packages/@aws-cdk/aws-apigatewayv2-alpha/test/http/route.test.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ describe('HttpRoute', () => {
393393
'Fn::Join': [
394394
'',
395395
[
396-
'arn:aws:execute-api:',
396+
'arn:',
397+
{ Ref: 'AWS::Partition' },
398+
':execute-api:',
397399
{ Ref: 'AWS::Region' },
398400
':',
399401
{ Ref: 'AWS::AccountId' },
@@ -444,7 +446,9 @@ describe('HttpRoute', () => {
444446
'Fn::Join': [
445447
'',
446448
[
447-
'arn:aws:execute-api:',
449+
'arn:',
450+
{ Ref: 'AWS::Partition' },
451+
':execute-api:',
448452
{ Ref: 'AWS::Region' },
449453
':',
450454
{ Ref: 'AWS::AccountId' },
@@ -458,7 +462,9 @@ describe('HttpRoute', () => {
458462
'Fn::Join': [
459463
'',
460464
[
461-
'arn:aws:execute-api:',
465+
'arn:',
466+
{ Ref: 'AWS::Partition' },
467+
':execute-api:',
462468
{ Ref: 'AWS::Region' },
463469
':',
464470
{ Ref: 'AWS::AccountId' },
@@ -507,7 +513,9 @@ describe('HttpRoute', () => {
507513
'Fn::Join': [
508514
'',
509515
[
510-
'arn:aws:execute-api:',
516+
'arn:',
517+
{ Ref: 'AWS::Partition' },
518+
':execute-api:',
511519
{ Ref: 'AWS::Region' },
512520
':',
513521
{ Ref: 'AWS::AccountId' },
@@ -580,7 +588,9 @@ describe('HttpRoute', () => {
580588
// THEN
581589
expect(stack.resolve(route.routeArn)).toEqual({
582590
'Fn::Join': ['', [
583-
'arn:aws:execute-api:',
591+
'arn:',
592+
{ Ref: 'AWS::Partition' },
593+
':execute-api:',
584594
{ Ref: 'AWS::Region' },
585595
':',
586596
{ Ref: 'AWS::AccountId' },
@@ -605,7 +615,9 @@ describe('HttpRoute', () => {
605615
// THEN
606616
expect(stack.resolve(route.routeArn)).toEqual({
607617
'Fn::Join': ['', [
608-
'arn:aws:execute-api:',
618+
'arn:',
619+
{ Ref: 'AWS::Partition' },
620+
':execute-api:',
609621
{ Ref: 'AWS::Region' },
610622
':',
611623
{ Ref: 'AWS::AccountId' },

packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/integ.iam.js.snapshot/IntegApiGatewayV2Iam.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "20.0.0",
2+
"version": "31.0.0",
33
"files": {
4-
"7332d1f16eb3c30dc1e90813757b35ed0f36282e60246f0d439a027d7963089a": {
4+
"b46d250c47897b59c971b488d6f6bb6f29b101efdb994a0f5e4e547b8dafb886": {
55
"source": {
66
"path": "IntegApiGatewayV2Iam.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "7332d1f16eb3c30dc1e90813757b35ed0f36282e60246f0d439a027d7963089a.json",
12+
"objectKey": "b46d250c47897b59c971b488d6f6bb6f29b101efdb994a0f5e4e547b8dafb886.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/integ.iam.js.snapshot/IntegApiGatewayV2Iam.template.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
"Fn::Join": [
1717
"",
1818
[
19-
"arn:aws:execute-api:",
19+
"arn:",
20+
{
21+
"Ref": "AWS::Partition"
22+
},
23+
":execute-api:",
2024
{
2125
"Ref": "AWS::Region"
2226
},
@@ -36,7 +40,11 @@
3640
"Fn::Join": [
3741
"",
3842
[
39-
"arn:aws:execute-api:",
43+
"arn:",
44+
{
45+
"Ref": "AWS::Partition"
46+
},
47+
":execute-api:",
4048
{
4149
"Ref": "AWS::Region"
4250
},
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"20.0.0"}
1+
{"version":"31.0.0"}

packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/integ.iam.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "20.0.0",
2+
"version": "31.0.0",
33
"testCases": {
44
"integ.iam": {
55
"stacks": [

packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/integ.iam.js.snapshot/manifest.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
2-
"version": "20.0.0",
2+
"version": "31.0.0",
33
"artifacts": {
4-
"Tree": {
5-
"type": "cdk:tree",
6-
"properties": {
7-
"file": "tree.json"
8-
}
9-
},
104
"IntegApiGatewayV2Iam.assets": {
115
"type": "cdk:asset-manifest",
126
"properties": {
@@ -23,7 +17,7 @@
2317
"validateOnSynth": false,
2418
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2519
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/7332d1f16eb3c30dc1e90813757b35ed0f36282e60246f0d439a027d7963089a.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/b46d250c47897b59c971b488d6f6bb6f29b101efdb994a0f5e4e547b8dafb886.json",
2721
"requiresBootstrapStackVersion": 6,
2822
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2923
"additionalDependencies": [
@@ -131,6 +125,12 @@
131125
]
132126
},
133127
"displayName": "IntegApiGatewayV2Iam"
128+
},
129+
"Tree": {
130+
"type": "cdk:tree",
131+
"properties": {
132+
"file": "tree.json"
133+
}
134134
}
135135
}
136136
}

0 commit comments

Comments
 (0)