Skip to content

Commit 5be88a3

Browse files
authored
feat(events-targets): add support for AppSync as an EventBridge rule target (#29584)
### Reason for this change Introduces support to configure AppSync GraphQLAPI as an EventBridge target. - announcement: https://aws.amazon.com/about-aws/whats-new/2024/01/amazon-eventbridge-appsync-target-buses/ - documentation: https://docs.aws.amazon.com/eventbridge/latest/userguide/target-appsync.html ### Description of changes - Expose `GraphQLEndpointArn` attribute in L2 GraphQLAPI construct - Implement `events.IRuleTarget` for `AppSync` ```ts rule.addTarget(new targets.AppSync(api, { graphQLOperation: 'mutation Publish($message: String!){ publish(message: $message) { message } }', variables: events.RuleTargetInput.fromObject({ message: 'hello world', }), deadLetterQueue: queue, })); ``` ### Description of how you validated changes unit test and integration tests ### Issue Solves #29884 ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 30f0db6 commit 5be88a3

File tree

20 files changed

+1715
-53
lines changed

20 files changed

+1715
-53
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type Event {
2+
message: String
3+
}
4+
type Query {
5+
getTests: [Event]!
6+
}
7+
type Mutation {
8+
publish(message: String!): Event
9+
}
10+
11+
type Subscription {
12+
onPublish: Event @aws_subscribe(mutations: ["publish"])
13+
}

packages/@aws-cdk-testing/framework-integ/test/aws-events-targets/test/appsync/integ.appsync-events.js.snapshot/aws-cdk-aws-appsync-target-integ.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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
{
2+
"Resources": {
3+
"baseApiCDA4D43A": {
4+
"Type": "AWS::AppSync::GraphQLApi",
5+
"Properties": {
6+
"AuthenticationType": "AWS_IAM",
7+
"Name": "aws-cdk-aws-appsync-target-integ-api"
8+
}
9+
},
10+
"baseApiSchemaB12C7BB0": {
11+
"Type": "AWS::AppSync::GraphQLSchema",
12+
"Properties": {
13+
"ApiId": {
14+
"Fn::GetAtt": [
15+
"baseApiCDA4D43A",
16+
"ApiId"
17+
]
18+
},
19+
"Definition": "type Event {\n message: String\n}\ntype Query {\n getTests: [Event]!\n}\ntype Mutation {\n publish(message: String!): Event\n}\n\ntype Subscription {\n onPublish: Event @aws_subscribe(mutations: [\"publish\"])\n}\n"
20+
}
21+
},
22+
"baseApinone7DDDEE3D": {
23+
"Type": "AWS::AppSync::DataSource",
24+
"Properties": {
25+
"ApiId": {
26+
"Fn::GetAtt": [
27+
"baseApiCDA4D43A",
28+
"ApiId"
29+
]
30+
},
31+
"Name": "none",
32+
"Type": "NONE"
33+
}
34+
},
35+
"baseApipublisherC3F47EA2": {
36+
"Type": "AWS::AppSync::Resolver",
37+
"Properties": {
38+
"ApiId": {
39+
"Fn::GetAtt": [
40+
"baseApiCDA4D43A",
41+
"ApiId"
42+
]
43+
},
44+
"Code": "export const request = (ctx) => ({payload: null})\nexport const response = (ctx) => ctx.args.message",
45+
"DataSourceName": "none",
46+
"FieldName": "publish",
47+
"Kind": "UNIT",
48+
"Runtime": {
49+
"Name": "APPSYNC_JS",
50+
"RuntimeVersion": "1.0.0"
51+
},
52+
"TypeName": "Mutation"
53+
},
54+
"DependsOn": [
55+
"baseApinone7DDDEE3D",
56+
"baseApiSchemaB12C7BB0"
57+
]
58+
},
59+
"baseApiEventsRoleAC472BD7": {
60+
"Type": "AWS::IAM::Role",
61+
"Properties": {
62+
"AssumeRolePolicyDocument": {
63+
"Statement": [
64+
{
65+
"Action": "sts:AssumeRole",
66+
"Effect": "Allow",
67+
"Principal": {
68+
"Service": "events.amazonaws.com"
69+
}
70+
}
71+
],
72+
"Version": "2012-10-17"
73+
}
74+
}
75+
},
76+
"baseApiEventsRoleDefaultPolicy94199357": {
77+
"Type": "AWS::IAM::Policy",
78+
"Properties": {
79+
"PolicyDocument": {
80+
"Statement": [
81+
{
82+
"Action": "appsync:GraphQL",
83+
"Effect": "Allow",
84+
"Resource": {
85+
"Fn::Join": [
86+
"",
87+
[
88+
"arn:",
89+
{
90+
"Ref": "AWS::Partition"
91+
},
92+
":appsync:",
93+
{
94+
"Ref": "AWS::Region"
95+
},
96+
":",
97+
{
98+
"Ref": "AWS::AccountId"
99+
},
100+
":apis/",
101+
{
102+
"Fn::GetAtt": [
103+
"baseApiCDA4D43A",
104+
"ApiId"
105+
]
106+
},
107+
"/types/Mutation/*"
108+
]
109+
]
110+
}
111+
}
112+
],
113+
"Version": "2012-10-17"
114+
},
115+
"PolicyName": "baseApiEventsRoleDefaultPolicy94199357",
116+
"Roles": [
117+
{
118+
"Ref": "baseApiEventsRoleAC472BD7"
119+
}
120+
]
121+
}
122+
},
123+
"Queue4A7E3555": {
124+
"Type": "AWS::SQS::Queue",
125+
"UpdateReplacePolicy": "Delete",
126+
"DeletionPolicy": "Delete"
127+
},
128+
"QueuePolicy25439813": {
129+
"Type": "AWS::SQS::QueuePolicy",
130+
"Properties": {
131+
"PolicyDocument": {
132+
"Statement": [
133+
{
134+
"Action": "sqs:SendMessage",
135+
"Condition": {
136+
"ArnEquals": {
137+
"aws:SourceArn": {
138+
"Fn::GetAtt": [
139+
"TimerBF6F831F",
140+
"Arn"
141+
]
142+
}
143+
}
144+
},
145+
"Effect": "Allow",
146+
"Principal": {
147+
"Service": "events.amazonaws.com"
148+
},
149+
"Resource": {
150+
"Fn::GetAtt": [
151+
"Queue4A7E3555",
152+
"Arn"
153+
]
154+
},
155+
"Sid": "AllowEventRuleawscdkawsappsynctargetintegTimer2A2187F8"
156+
}
157+
],
158+
"Version": "2012-10-17"
159+
},
160+
"Queues": [
161+
{
162+
"Ref": "Queue4A7E3555"
163+
}
164+
]
165+
}
166+
},
167+
"TimerBF6F831F": {
168+
"Type": "AWS::Events::Rule",
169+
"Properties": {
170+
"ScheduleExpression": "rate(1 minute)",
171+
"State": "ENABLED",
172+
"Targets": [
173+
{
174+
"AppSyncParameters": {
175+
"GraphQLOperation": "mutation Publish($message: String!){ publish(message: $message) { message } }"
176+
},
177+
"Arn": {
178+
"Fn::GetAtt": [
179+
"baseApiCDA4D43A",
180+
"GraphQLEndpointArn"
181+
]
182+
},
183+
"DeadLetterConfig": {
184+
"Arn": {
185+
"Fn::GetAtt": [
186+
"Queue4A7E3555",
187+
"Arn"
188+
]
189+
}
190+
},
191+
"Id": "Target0",
192+
"Input": "{\"message\":\"hello world\"}",
193+
"RoleArn": {
194+
"Fn::GetAtt": [
195+
"baseApiEventsRoleAC472BD7",
196+
"Arn"
197+
]
198+
}
199+
}
200+
]
201+
}
202+
}
203+
},
204+
"Parameters": {
205+
"BootstrapVersion": {
206+
"Type": "AWS::SSM::Parameter::Value<String>",
207+
"Default": "/cdk-bootstrap/hnb659fds/version",
208+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
209+
}
210+
},
211+
"Rules": {
212+
"CheckBootstrapVersion": {
213+
"Assertions": [
214+
{
215+
"Assert": {
216+
"Fn::Not": [
217+
{
218+
"Fn::Contains": [
219+
[
220+
"1",
221+
"2",
222+
"3",
223+
"4",
224+
"5"
225+
],
226+
{
227+
"Ref": "BootstrapVersion"
228+
}
229+
]
230+
}
231+
]
232+
},
233+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
234+
}
235+
]
236+
}
237+
}
238+
}

packages/@aws-cdk-testing/framework-integ/test/aws-events-targets/test/appsync/integ.appsync-events.js.snapshot/awsappsyncintegDefaultTestDeployAssert7E101DC4.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-events-targets/test/appsync/integ.appsync-events.js.snapshot/awsappsyncintegDefaultTestDeployAssert7E101DC4.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-events-targets/test/appsync/integ.appsync-events.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-events-targets/test/appsync/integ.appsync-events.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)