-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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*
- Loading branch information
Showing
20 changed files
with
1,715 additions
and
53 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...aws-cdk-testing/framework-integ/test/aws-events-targets/test/appsync/appsync.test.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
type Event { | ||
message: String | ||
} | ||
type Query { | ||
getTests: [Event]! | ||
} | ||
type Mutation { | ||
publish(message: String!): Event | ||
} | ||
|
||
type Subscription { | ||
onPublish: Event @aws_subscribe(mutations: ["publish"]) | ||
} |
19 changes: 19 additions & 0 deletions
19
...est/appsync/integ.appsync-events.js.snapshot/aws-cdk-aws-appsync-target-integ.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
238 changes: 238 additions & 0 deletions
238
...t/appsync/integ.appsync-events.js.snapshot/aws-cdk-aws-appsync-target-integ.template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
{ | ||
"Resources": { | ||
"baseApiCDA4D43A": { | ||
"Type": "AWS::AppSync::GraphQLApi", | ||
"Properties": { | ||
"AuthenticationType": "AWS_IAM", | ||
"Name": "aws-cdk-aws-appsync-target-integ-api" | ||
} | ||
}, | ||
"baseApiSchemaB12C7BB0": { | ||
"Type": "AWS::AppSync::GraphQLSchema", | ||
"Properties": { | ||
"ApiId": { | ||
"Fn::GetAtt": [ | ||
"baseApiCDA4D43A", | ||
"ApiId" | ||
] | ||
}, | ||
"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" | ||
} | ||
}, | ||
"baseApinone7DDDEE3D": { | ||
"Type": "AWS::AppSync::DataSource", | ||
"Properties": { | ||
"ApiId": { | ||
"Fn::GetAtt": [ | ||
"baseApiCDA4D43A", | ||
"ApiId" | ||
] | ||
}, | ||
"Name": "none", | ||
"Type": "NONE" | ||
} | ||
}, | ||
"baseApipublisherC3F47EA2": { | ||
"Type": "AWS::AppSync::Resolver", | ||
"Properties": { | ||
"ApiId": { | ||
"Fn::GetAtt": [ | ||
"baseApiCDA4D43A", | ||
"ApiId" | ||
] | ||
}, | ||
"Code": "export const request = (ctx) => ({payload: null})\nexport const response = (ctx) => ctx.args.message", | ||
"DataSourceName": "none", | ||
"FieldName": "publish", | ||
"Kind": "UNIT", | ||
"Runtime": { | ||
"Name": "APPSYNC_JS", | ||
"RuntimeVersion": "1.0.0" | ||
}, | ||
"TypeName": "Mutation" | ||
}, | ||
"DependsOn": [ | ||
"baseApinone7DDDEE3D", | ||
"baseApiSchemaB12C7BB0" | ||
] | ||
}, | ||
"baseApiEventsRoleAC472BD7": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "events.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
} | ||
} | ||
}, | ||
"baseApiEventsRoleDefaultPolicy94199357": { | ||
"Type": "AWS::IAM::Policy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "appsync:GraphQL", | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":appsync:", | ||
{ | ||
"Ref": "AWS::Region" | ||
}, | ||
":", | ||
{ | ||
"Ref": "AWS::AccountId" | ||
}, | ||
":apis/", | ||
{ | ||
"Fn::GetAtt": [ | ||
"baseApiCDA4D43A", | ||
"ApiId" | ||
] | ||
}, | ||
"/types/Mutation/*" | ||
] | ||
] | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"PolicyName": "baseApiEventsRoleDefaultPolicy94199357", | ||
"Roles": [ | ||
{ | ||
"Ref": "baseApiEventsRoleAC472BD7" | ||
} | ||
] | ||
} | ||
}, | ||
"Queue4A7E3555": { | ||
"Type": "AWS::SQS::Queue", | ||
"UpdateReplacePolicy": "Delete", | ||
"DeletionPolicy": "Delete" | ||
}, | ||
"QueuePolicy25439813": { | ||
"Type": "AWS::SQS::QueuePolicy", | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sqs:SendMessage", | ||
"Condition": { | ||
"ArnEquals": { | ||
"aws:SourceArn": { | ||
"Fn::GetAtt": [ | ||
"TimerBF6F831F", | ||
"Arn" | ||
] | ||
} | ||
} | ||
}, | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "events.amazonaws.com" | ||
}, | ||
"Resource": { | ||
"Fn::GetAtt": [ | ||
"Queue4A7E3555", | ||
"Arn" | ||
] | ||
}, | ||
"Sid": "AllowEventRuleawscdkawsappsynctargetintegTimer2A2187F8" | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"Queues": [ | ||
{ | ||
"Ref": "Queue4A7E3555" | ||
} | ||
] | ||
} | ||
}, | ||
"TimerBF6F831F": { | ||
"Type": "AWS::Events::Rule", | ||
"Properties": { | ||
"ScheduleExpression": "rate(1 minute)", | ||
"State": "ENABLED", | ||
"Targets": [ | ||
{ | ||
"AppSyncParameters": { | ||
"GraphQLOperation": "mutation Publish($message: String!){ publish(message: $message) { message } }" | ||
}, | ||
"Arn": { | ||
"Fn::GetAtt": [ | ||
"baseApiCDA4D43A", | ||
"GraphQLEndpointArn" | ||
] | ||
}, | ||
"DeadLetterConfig": { | ||
"Arn": { | ||
"Fn::GetAtt": [ | ||
"Queue4A7E3555", | ||
"Arn" | ||
] | ||
} | ||
}, | ||
"Id": "Target0", | ||
"Input": "{\"message\":\"hello world\"}", | ||
"RoleArn": { | ||
"Fn::GetAtt": [ | ||
"baseApiEventsRoleAC472BD7", | ||
"Arn" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"Parameters": { | ||
"BootstrapVersion": { | ||
"Type": "AWS::SSM::Parameter::Value<String>", | ||
"Default": "/cdk-bootstrap/hnb659fds/version", | ||
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" | ||
} | ||
}, | ||
"Rules": { | ||
"CheckBootstrapVersion": { | ||
"Assertions": [ | ||
{ | ||
"Assert": { | ||
"Fn::Not": [ | ||
{ | ||
"Fn::Contains": [ | ||
[ | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5" | ||
], | ||
{ | ||
"Ref": "BootstrapVersion" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." | ||
} | ||
] | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...teg.appsync-events.js.snapshot/awsappsyncintegDefaultTestDeployAssert7E101DC4.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...g.appsync-events.js.snapshot/awsappsyncintegDefaultTestDeployAssert7E101DC4.template.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...ework-integ/test/aws-events-targets/test/appsync/integ.appsync-events.js.snapshot/cdk.out
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...rk-integ/test/aws-events-targets/test/appsync/integ.appsync-events.js.snapshot/integ.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.