Skip to content

Commit fe3cd45

Browse files
ohdemadeline-k
authored andcommitted
fix(appsync): can not use Tokens in the name of a DataSource (aws#22378)
Closes aws#18900 ---- ### All Submissions: * [ X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ X] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [X ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 232d275 commit fe3cd45

12 files changed

+519
-3
lines changed

Diff for: packages/@aws-cdk/aws-appsync/lib/data-source.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IFunction } from '@aws-cdk/aws-lambda';
55
import { IDomain as IOpenSearchDomain } from '@aws-cdk/aws-opensearchservice';
66
import { IServerlessCluster } from '@aws-cdk/aws-rds';
77
import { ISecret } from '@aws-cdk/aws-secretsmanager';
8-
import { IResolvable, Lazy, Stack } from '@aws-cdk/core';
8+
import { IResolvable, Lazy, Stack, Token } from '@aws-cdk/core';
99
import { Construct } from 'constructs';
1010
import { BaseAppsyncFunctionProps, AppsyncFunction } from './appsync-function';
1111
import { CfnDataSource } from './appsync.generated';
@@ -116,10 +116,11 @@ export abstract class BaseDataSource extends Construct {
116116
this.serviceRole = props.serviceRole || new Role(this, 'ServiceRole', { assumedBy: new ServicePrincipal('appsync') });
117117
}
118118
// Replace unsupported characters from DataSource name. The only allowed pattern is: {[_A-Za-z][_0-9A-Za-z]*}
119-
const name = (props.name ?? id).replace(/[\W]+/g, '');
119+
const name = (props.name ?? id);
120+
const supportedName = Token.isUnresolved(name) ? name : name.replace(/[\W]+/g, '');
120121
this.ds = new CfnDataSource(this, 'Resource', {
121122
apiId: props.api.apiId,
122-
name: name,
123+
name: supportedName,
123124
description: props.description,
124125
serviceRoleArn: this.serviceRole?.roleArn,
125126
...extended,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "21.0.0",
3+
"files": {
4+
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
5+
"source": {
6+
"path": "apiDefaultTestDeployAssert018781F2.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"Parameters": {
3+
"BootstrapVersion": {
4+
"Type": "AWS::SSM::Parameter::Value<String>",
5+
"Default": "/cdk-bootstrap/hnb659fds/version",
6+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
7+
}
8+
},
9+
"Rules": {
10+
"CheckBootstrapVersion": {
11+
"Assertions": [
12+
{
13+
"Assert": {
14+
"Fn::Not": [
15+
{
16+
"Fn::Contains": [
17+
[
18+
"1",
19+
"2",
20+
"3",
21+
"4",
22+
"5"
23+
],
24+
{
25+
"Ref": "BootstrapVersion"
26+
}
27+
]
28+
}
29+
]
30+
},
31+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
32+
}
33+
]
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"21.0.0"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "21.0.0",
3+
"testCases": {
4+
"api/DefaultTest": {
5+
"stacks": [
6+
"stack"
7+
],
8+
"assertionStack": "api/DefaultTest/DeployAssert",
9+
"assertionStackName": "apiDefaultTestDeployAssert018781F2"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
"version": "21.0.0",
3+
"artifacts": {
4+
"Tree": {
5+
"type": "cdk:tree",
6+
"properties": {
7+
"file": "tree.json"
8+
}
9+
},
10+
"stack.assets": {
11+
"type": "cdk:asset-manifest",
12+
"properties": {
13+
"file": "stack.assets.json",
14+
"requiresBootstrapStackVersion": 6,
15+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
16+
}
17+
},
18+
"stack": {
19+
"type": "aws:cloudformation:stack",
20+
"environment": "aws://unknown-account/unknown-region",
21+
"properties": {
22+
"templateFile": "stack.template.json",
23+
"validateOnSynth": false,
24+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
25+
"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}/f042b3cf231d4b437b4eaeb1389edd958e4640394bc53a918ce5c08751499411.json",
27+
"requiresBootstrapStackVersion": 6,
28+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
29+
"additionalDependencies": [
30+
"stack.assets"
31+
],
32+
"lookupRole": {
33+
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
34+
"requiresBootstrapStackVersion": 8,
35+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
36+
}
37+
},
38+
"dependencies": [
39+
"stack.assets"
40+
],
41+
"metadata": {
42+
"/stack/NoneAPI/Resource": [
43+
{
44+
"type": "aws:cdk:logicalId",
45+
"data": "NoneAPI55E3D0D9"
46+
}
47+
],
48+
"/stack/NoneAPI/Schema": [
49+
{
50+
"type": "aws:cdk:logicalId",
51+
"data": "NoneAPISchema60A29796"
52+
}
53+
],
54+
"/stack/NoneAPI/DefaultApiKey": [
55+
{
56+
"type": "aws:cdk:logicalId",
57+
"data": "NoneAPIDefaultApiKey67B964CA"
58+
}
59+
],
60+
"/stack/NoneAPI/NoneDS/Resource": [
61+
{
62+
"type": "aws:cdk:logicalId",
63+
"data": "NoneAPINoneDSCC0A2012"
64+
}
65+
],
66+
"/stack/BootstrapVersion": [
67+
{
68+
"type": "aws:cdk:logicalId",
69+
"data": "BootstrapVersion"
70+
}
71+
],
72+
"/stack/CheckBootstrapVersion": [
73+
{
74+
"type": "aws:cdk:logicalId",
75+
"data": "CheckBootstrapVersion"
76+
}
77+
]
78+
},
79+
"displayName": "stack"
80+
},
81+
"apiDefaultTestDeployAssert018781F2.assets": {
82+
"type": "cdk:asset-manifest",
83+
"properties": {
84+
"file": "apiDefaultTestDeployAssert018781F2.assets.json",
85+
"requiresBootstrapStackVersion": 6,
86+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
87+
}
88+
},
89+
"apiDefaultTestDeployAssert018781F2": {
90+
"type": "aws:cloudformation:stack",
91+
"environment": "aws://unknown-account/unknown-region",
92+
"properties": {
93+
"templateFile": "apiDefaultTestDeployAssert018781F2.template.json",
94+
"validateOnSynth": false,
95+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
96+
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
97+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
98+
"requiresBootstrapStackVersion": 6,
99+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
100+
"additionalDependencies": [
101+
"apiDefaultTestDeployAssert018781F2.assets"
102+
],
103+
"lookupRole": {
104+
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
105+
"requiresBootstrapStackVersion": 8,
106+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
107+
}
108+
},
109+
"dependencies": [
110+
"apiDefaultTestDeployAssert018781F2.assets"
111+
],
112+
"metadata": {
113+
"/api/DefaultTest/DeployAssert/BootstrapVersion": [
114+
{
115+
"type": "aws:cdk:logicalId",
116+
"data": "BootstrapVersion"
117+
}
118+
],
119+
"/api/DefaultTest/DeployAssert/CheckBootstrapVersion": [
120+
{
121+
"type": "aws:cdk:logicalId",
122+
"data": "CheckBootstrapVersion"
123+
}
124+
]
125+
},
126+
"displayName": "api/DefaultTest/DeployAssert"
127+
}
128+
}
129+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "21.0.0",
3+
"files": {
4+
"f042b3cf231d4b437b4eaeb1389edd958e4640394bc53a918ce5c08751499411": {
5+
"source": {
6+
"path": "stack.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "f042b3cf231d4b437b4eaeb1389edd958e4640394bc53a918ce5c08751499411.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"Resources": {
3+
"NoneAPI55E3D0D9": {
4+
"Type": "AWS::AppSync::GraphQLApi",
5+
"Properties": {
6+
"AuthenticationType": "API_KEY",
7+
"Name": "NoneAPI"
8+
}
9+
},
10+
"NoneAPISchema60A29796": {
11+
"Type": "AWS::AppSync::GraphQLSchema",
12+
"Properties": {
13+
"ApiId": {
14+
"Fn::GetAtt": [
15+
"NoneAPI55E3D0D9",
16+
"ApiId"
17+
]
18+
},
19+
"Definition": "type test {\n version: String!\n}\ntype Query {\n getTests: [test]!\n}\ntype Mutation {\n addTest(version: String!): test\n}\n"
20+
}
21+
},
22+
"NoneAPIDefaultApiKey67B964CA": {
23+
"Type": "AWS::AppSync::ApiKey",
24+
"Properties": {
25+
"ApiId": {
26+
"Fn::GetAtt": [
27+
"NoneAPI55E3D0D9",
28+
"ApiId"
29+
]
30+
}
31+
},
32+
"DependsOn": [
33+
"NoneAPISchema60A29796"
34+
]
35+
},
36+
"NoneAPINoneDSCC0A2012": {
37+
"Type": "AWS::AppSync::DataSource",
38+
"Properties": {
39+
"ApiId": {
40+
"Fn::GetAtt": [
41+
"NoneAPI55E3D0D9",
42+
"ApiId"
43+
]
44+
},
45+
"Name": "NoneDS",
46+
"Type": "NONE"
47+
}
48+
}
49+
},
50+
"Parameters": {
51+
"BootstrapVersion": {
52+
"Type": "AWS::SSM::Parameter::Value<String>",
53+
"Default": "/cdk-bootstrap/hnb659fds/version",
54+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
55+
}
56+
},
57+
"Rules": {
58+
"CheckBootstrapVersion": {
59+
"Assertions": [
60+
{
61+
"Assert": {
62+
"Fn::Not": [
63+
{
64+
"Fn::Contains": [
65+
[
66+
"1",
67+
"2",
68+
"3",
69+
"4",
70+
"5"
71+
],
72+
{
73+
"Ref": "BootstrapVersion"
74+
}
75+
]
76+
}
77+
]
78+
},
79+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
80+
}
81+
]
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)