Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events-targets): add support for AppSync as an EventBridge rule target #29584

Merged
merged 35 commits into from
May 13, 2024

Conversation

onlybakam
Copy link
Contributor

@onlybakam onlybakam commented Mar 22, 2024

Reason for this change

Introduces support to configure AppSync GraphQLAPI as an EventBridge target.

Description of changes

  • Expose GraphQLEndpointArn attribute in L2 GraphQLAPI construct
  • Implement events.IRuleTarget for AppSync
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


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Mar 22, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team March 22, 2024 21:29
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Mar 25, 2024
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍
Left some suggestions for minor adjustments

packages/aws-cdk-lib/aws-events-targets/README.md Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-events-targets/lib/appsync.ts Outdated Show resolved Hide resolved
if (this.props.deadLetterQueue) {
addToDeadLetterQueueResourcePolicy(rule, this.props.deadLetterQueue);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From docs:

EventBridge supports AWS AppSync public GraphQL APIs. EventBridge does not currently support AWS AppSync Private APIs.

Shouldn't we validate visibility: 'GLOBAL' as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added check.

packages/aws-cdk-lib/aws-events-targets/lib/index.ts Outdated Show resolved Hide resolved
const role = this.props.eventRole || singletonEventRole(this.appsyncApi);

// if a role was not provided, attach a permission
if (!this.props.eventRole) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!this.props.eventRole) {
if (!this.props.eventRole && this.props.mutationFields.length) {

Should we grant permissions if there are no mutationFields?
Also, is it ok to assume that the provided eventRole will always have the necessary permissions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed mutationFields, developer needs to provide the proper permissions if they specify the role directly. If eventRole is provided by customer, there's no check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

developer needs to provide the proper permissions if they specify the role directly

Can you please add it to the README with an example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

packages/aws-cdk-lib/aws-events-targets/lib/appsync.ts Outdated Show resolved Hide resolved
/**
* The variables that are include in the GraphQL operation.
*/
readonly variables: events.RuleTargetInput;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
readonly variables: events.RuleTargetInput;
readonly variables?: events.RuleTargetInput;

Can we expect GraphQL queries without variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to optional

Comment on lines 9 to 10
// GIVEN
let stack: cdk.Stack;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// GIVEN
let stack: cdk.Stack;
describe('AppSync GraphQL API target', () => {
let stack: cdk.Stack;
...

Let's wrap it in a describe to keep it more organized.
Also, can you please remove the commented dead-code in the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 1, 2024
@gracelu0
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented May 11, 2024

update

❌ Mergify doesn't have permission to update

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/github-merit-badger.yml without workflows permission

@mergify mergify bot dismissed gracelu0’s stale review May 11, 2024 00:08

Pull request has been modified.

Copy link
Contributor

mergify bot commented May 12, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 87f427d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented May 12, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@gracelu0
Copy link
Contributor

@Mergifyio queue

Copy link
Contributor

mergify bot commented May 13, 2024

queue

🛑 The pull request has been removed from the queue default

Pull request #29584 has been dequeued. GitHub can't merge the pull request for now.. GitHub can't merge the pull request for an unknown reason. You should retry later..

You can take a look at Queue: Embarked in merge queue check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

@gracelu0
Copy link
Contributor

@Mergifyio refresh

Copy link
Contributor

mergify bot commented May 13, 2024

refresh

✅ Pull request refreshed

@mergify mergify bot merged commit 5be88a3 into aws:main May 13, 2024
9 checks passed
@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants