hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.55k stars 8.96k forks source link

[Enhancement]: Appsync targets for aws_cloudwatch_event_target #36369

Open jarrod-mg opened 3 months ago

jarrod-mg commented 3 months ago

Description

AWS Cloudwatch Event Targets can use AWS AppSync GraphQL APIs as a target. To do so, you need to set the ARN to, for example, "arn:aws:appsync:ap-southeast-2:0123456789012:endpoints/graphql-api/GRAPHQLENDPOINTIDSTRING", and also set a block "AppSyncParameters". The cloudformation inside a cloudwatch event rule looks like:

  Targets:
        - Id: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
          Arn: >-
            arn:aws:appsync:ap-southeast-2:xxxxxxxxxxx:endpoints/graphql-api/xxxxxxxxxxxxxxxxxxxxxx
          RoleArn: >-
            arn:aws:iam::xxxxxxxxxxx:role/service-role/Amazon_EventBridge_Invoke_AppSync_xxxxxxxxxxx
          InputTransformer:
            InputPathsMap:
              field: $.detail.field
            InputTemplate: |-
              {
                "input": {"hash": "<field>"}
              }
          AppSyncParameters:
            GraphQLOperation: >-
              mutation
              myMutation($input:MyInput!){theMutation(input:$input){
                hash
              }}

Affected Resource(s) and/or Data Source(s)

Potential Terraform Configuration

resource "aws_cloudwatch_event_target" "target" {
  rule = "MyRuleName"
  arn  = "arn:aws:appsync:ap-southeast-2:0123456789012:endpoints/graphql-api/GRAPHQLENDPOINTIDSTRING"
  event_bus_name = "MyEventBus"
  role_arn = aws_iam_role.MyRole.arn

  input_transformer {
    input_paths = {
      "thing": "$.detail.thing"
    }
    input_template = jsonencode({
      input: {
        thing: "<thing>"
      }
    }
  }

  app_sync_parameters {
    graphql_operation = "mutation myMutation($input: Input!){theMutation(input: $input){ output }}"
}

References

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-appsyncparameters.html

Would you like to implement a fix?

No

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

thelegendtubaguy commented 1 month ago

Came across this looking to add a target for an appsync mutation. The docs are incredibly confusing around this from the eventbridge side. They mention using the "GraphQL endpoint URL", which I was surprised wasn't a thing when I describe my graphql API with the command line. The only real references I can find to that are in cloudformation and CDK land: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#aws-resource-appsync-graphqlapi-return-values

I would recommend that in addition to this EventBridge target update, that the appsync graphql resource be updated to provide that special snowflake ARN as well which seems needed to support this.

Also very sad that this wasn't a day 0 release with Terraform. This is a huge win for the serverless peeps.

Oltier commented 2 weeks ago

Feel free to give a 👍 to my PR if you also find this event rule target useful 😁 https://github.com/hashicorp/terraform-provider-aws/pull/37773