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
onlybakam and others added 5 commits April 3, 2024 15:41
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation dismissed their stale review May 2, 2024 00:43

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

packages/aws-cdk-lib/aws-appsync/lib/graphqlapi-base.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-appsync/lib/graphqlapi.ts Outdated Show resolved Hide resolved
message: events.EventField.fromPath('$.detail'),
}),
}));
}).toThrow('You must have AWS_IAM authorization mode enabled on your API to configure an AppSync target');
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the correct error to be checking for this test case? should be it expecting "throw new Error('You must have a valid graphQLEndpointArn set')" instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right. fixing setup and check.

const sec_api = new appsync.GraphqlApi(stack, 'sec_api', {
name: 'no_iam_api',
definition: appsync.Definition.fromFile(path.join(__dirname, 'appsync.test.graphql')),
authorizationConfig: { additionalAuthorizationModes: [{ authorizationType: appsync.AuthorizationType.IAM }] },
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if the secondary auth type is not IAM ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IAM needs to be one of the supported modes. either primary or secondary. if none are configured as IAM the target definition should fail.


```ts
import * as appsync from 'aws-cdk-lib/aws-appsync';
declare const api: appsync.GraphqlApi;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should include the instantiation of GraphqlApi to make the example more complete, especially if there are properties that need to be configured to a certain value, e.g. AWS_IAM for authorization

Co-authored-by: Grace Luo <54298030+gracelu0@users.noreply.github.com>
@mergify mergify bot dismissed gracelu0’s stale review May 8, 2024 00:25

Pull request has been modified.

onlybakam and others added 3 commits May 7, 2024 17:25
gracelu0
gracelu0 previously approved these changes May 11, 2024
Copy link
Contributor

@gracelu0 gracelu0 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for contributing! :)

Copy link
Contributor

mergify bot commented May 11, 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

None yet

5 participants