Skip to content

Commit 04e5480

Browse files
authored
fix(appsync): add dependency to logretention for graphql apis log group (#28548)
This change adds a dependency to log retention if logconfig is set for `GraphqlApi`. This in turn avoids the race condition when subsequent resources refer to the log group property of `GraphqlApi.logGroup` logGroup is now referring to the custom resource's output log ARN and further resources will depend on the custom resource to be created first. Closes #26564 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent bb50f97 commit 04e5480

File tree

25 files changed

+6088
-3646
lines changed

25 files changed

+6088
-3646
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.appsync-logmetrics.js.snapshot/AppSyncLogMetrics.assets.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
{
2+
"Resources": {
3+
"ApiApiLogsRole90293F72": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "appsync.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"ManagedPolicyArns": [
19+
{
20+
"Fn::Join": [
21+
"",
22+
[
23+
"arn:",
24+
{
25+
"Ref": "AWS::Partition"
26+
},
27+
":iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs"
28+
]
29+
]
30+
}
31+
]
32+
}
33+
},
34+
"ApiF70053CD": {
35+
"Type": "AWS::AppSync::GraphQLApi",
36+
"Properties": {
37+
"AuthenticationType": "API_KEY",
38+
"LogConfig": {
39+
"CloudWatchLogsRoleArn": {
40+
"Fn::GetAtt": [
41+
"ApiApiLogsRole90293F72",
42+
"Arn"
43+
]
44+
},
45+
"FieldLogLevel": "NONE"
46+
},
47+
"Name": "IntegLogRetention"
48+
}
49+
},
50+
"ApiSchema510EECD7": {
51+
"Type": "AWS::AppSync::GraphQLSchema",
52+
"Properties": {
53+
"ApiId": {
54+
"Fn::GetAtt": [
55+
"ApiF70053CD",
56+
"ApiId"
57+
]
58+
},
59+
"Definition": "type test {\n version: String!\n}\ntype Query {\n getTests: [test]!\n}\ntype Mutation {\n addTest(version: String!): test\n}\n"
60+
}
61+
},
62+
"ApiDefaultApiKeyF991C37B": {
63+
"Type": "AWS::AppSync::ApiKey",
64+
"Properties": {
65+
"ApiId": {
66+
"Fn::GetAtt": [
67+
"ApiF70053CD",
68+
"ApiId"
69+
]
70+
}
71+
},
72+
"DependsOn": [
73+
"ApiSchema510EECD7"
74+
]
75+
},
76+
"ApiLogRetention94272E33": {
77+
"Type": "Custom::LogRetention",
78+
"Properties": {
79+
"ServiceToken": {
80+
"Fn::GetAtt": [
81+
"LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A",
82+
"Arn"
83+
]
84+
},
85+
"LogGroupName": {
86+
"Fn::Join": [
87+
"",
88+
[
89+
"/aws/appsync/apis/",
90+
{
91+
"Fn::GetAtt": [
92+
"ApiF70053CD",
93+
"ApiId"
94+
]
95+
}
96+
]
97+
]
98+
},
99+
"RetentionInDays": 7
100+
}
101+
},
102+
"ApiLogGroupMetricFilter996FD830": {
103+
"Type": "AWS::Logs::MetricFilter",
104+
"Properties": {
105+
"FilterPattern": "{ $.fieldName = \"myQuery\" && $.fieldInError IS TRUE }",
106+
"LogGroupName": {
107+
"Fn::GetAtt": [
108+
"ApiLogRetention94272E33",
109+
"LogGroupName"
110+
]
111+
},
112+
"MetricTransformations": [
113+
{
114+
"MetricName": "ErrorCount",
115+
"MetricNamespace": "MyNamespace",
116+
"MetricValue": "1"
117+
}
118+
]
119+
}
120+
},
121+
"LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB": {
122+
"Type": "AWS::IAM::Role",
123+
"Properties": {
124+
"AssumeRolePolicyDocument": {
125+
"Statement": [
126+
{
127+
"Action": "sts:AssumeRole",
128+
"Effect": "Allow",
129+
"Principal": {
130+
"Service": "lambda.amazonaws.com"
131+
}
132+
}
133+
],
134+
"Version": "2012-10-17"
135+
},
136+
"ManagedPolicyArns": [
137+
{
138+
"Fn::Join": [
139+
"",
140+
[
141+
"arn:",
142+
{
143+
"Ref": "AWS::Partition"
144+
},
145+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
146+
]
147+
]
148+
}
149+
]
150+
}
151+
},
152+
"LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB": {
153+
"Type": "AWS::IAM::Policy",
154+
"Properties": {
155+
"PolicyDocument": {
156+
"Statement": [
157+
{
158+
"Action": [
159+
"logs:DeleteRetentionPolicy",
160+
"logs:PutRetentionPolicy"
161+
],
162+
"Effect": "Allow",
163+
"Resource": "*"
164+
}
165+
],
166+
"Version": "2012-10-17"
167+
},
168+
"PolicyName": "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB",
169+
"Roles": [
170+
{
171+
"Ref": "LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB"
172+
}
173+
]
174+
}
175+
},
176+
"LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A": {
177+
"Type": "AWS::Lambda::Function",
178+
"Properties": {
179+
"Handler": "index.handler",
180+
"Runtime": "nodejs18.x",
181+
"Timeout": 900,
182+
"Code": {
183+
"S3Bucket": {
184+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
185+
},
186+
"S3Key": "e4afb15788ec44ed9ff3377e1d131ba2768d7b2e2931bc000d1f2005879b3035.zip"
187+
},
188+
"Role": {
189+
"Fn::GetAtt": [
190+
"LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB",
191+
"Arn"
192+
]
193+
}
194+
},
195+
"DependsOn": [
196+
"LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB",
197+
"LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB"
198+
]
199+
}
200+
},
201+
"Parameters": {
202+
"BootstrapVersion": {
203+
"Type": "AWS::SSM::Parameter::Value<String>",
204+
"Default": "/cdk-bootstrap/hnb659fds/version",
205+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
206+
}
207+
},
208+
"Rules": {
209+
"CheckBootstrapVersion": {
210+
"Assertions": [
211+
{
212+
"Assert": {
213+
"Fn::Not": [
214+
{
215+
"Fn::Contains": [
216+
[
217+
"1",
218+
"2",
219+
"3",
220+
"4",
221+
"5"
222+
],
223+
{
224+
"Ref": "BootstrapVersion"
225+
}
226+
]
227+
}
228+
]
229+
},
230+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
231+
}
232+
]
233+
}
234+
}
235+
}

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.appsync-logmetrics.js.snapshot/IntegDefaultTestDeployAssert4E6713E1.assets.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.appsync-logmetrics.js.snapshot/IntegDefaultTestDeployAssert4E6713E1.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.appsync-logmetrics.js.snapshot/asset.e4afb15788ec44ed9ff3377e1d131ba2768d7b2e2931bc000d1f2005879b3035/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.appsync-logmetrics.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-appsync/test/integ.appsync-logmetrics.js.snapshot/integ.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)