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

Support direct resolvers in aws_appsync_resolver resource #14488

Closed
npellegrin opened this issue Aug 6, 2020 · 3 comments · Fixed by #14710
Closed

Support direct resolvers in aws_appsync_resolver resource #14488

npellegrin opened this issue Aug 6, 2020 · 3 comments · Fixed by #14710
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/appsync Issues and PRs that pertain to the appsync service.

Comments

@npellegrin
Copy link
Contributor

npellegrin commented Aug 6, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

AWS now supports direct lambda resolvers in AppSync.

Developers can now send directly the request and build the response in a Lambda function, without the need to write VTL ( Apache Velocity Template Language) templates.

New or Affected Resource(s)

  • aws_appsync_resolver

Potential Terraform Configuration

The fields request_template and response_template are now optional.
Sugested code:

resource "aws_appsync_resolver" "test" {
  api_id      = aws_appsync_graphql_api.test.id
  field       = "singlePost"
  type        = "Query"
  data_source = aws_appsync_datasource.lambda.name
}

References

AWS blog post:

Change in botocore (change available from 1.17.36):

Change in aws-sdk-go (change available from 1.33.20):

@npellegrin npellegrin added the enhancement Requests to existing resources that expand the functionality or scope. label Aug 6, 2020
@ghost ghost added the service/appsync Issues and PRs that pertain to the appsync service. label Aug 6, 2020
@ewbankkit
Copy link
Contributor

@antonbabenko
Copy link
Contributor

antonbabenko commented Aug 21, 2020

It turns out that direct lambda resolvers are using VTL templates under the hood, too.

This code is a workaround unless request_template and response_template are optional (#14710):

resource "aws_appsync_resolver" "lambda" {
  api_id      = aws_appsync_graphql_api.this.id
  field       = "getLayer"
  type        = "Query"
  data_source = aws_appsync_datasource.lambda.name

  request_template = <<-EOF
  {
    "version" : "2017-02-28",
    "operation": "Invoke",
    "payload": {
      "arguments": $util.toJson($ctx.arguments),
      "identity": $util.toJson($ctx.identity),
      "source": $util.toJson($ctx.source),
      "request": $util.toJson($ctx.request),
      "prev": $util.toJson($ctx.prev),
      "info": {
          "selectionSetList": $util.toJson($ctx.info.selectionSetList),
          "selectionSetGraphQL": $util.toJson($ctx.info.selectionSetGraphQL),
          "parentTypeName": $util.toJson($ctx.info.parentTypeName),
          "fieldName": $util.toJson($ctx.info.fieldName),
          "variables": $util.toJson($ctx.info.variables)
      },
      "stash": $util.toJson($ctx.stash)
    }
  }
  EOF

  response_template = <<-EOF
  $util.toJson($ctx.result)
  EOF
}

@bflad bflad self-assigned this Apr 29, 2021
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/appsync Issues and PRs that pertain to the appsync service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants