Reputation: 71
I have a graphQL server deployed with aws appsync. The thing is that our customers prefer a standard REST API. I'm looking for the simplest way to wrap graphQL query with REST API.
I'm considering using Amazon api gateway to make a REST endpoint, and integrate lambda behind the api gateway. In that way I can let lambda functions to send a fixed graphQL query/mutations and modify the response.
However as you can see from below image, I found AWS Service integration option in Amazon API gateway. I'm wondering whether I can integrate appsync to api gateway directly without using lambda. I searched it from aws documents but couldn't find any related information.
Amazon api gateway setup capture:
Upvotes: 5
Views: 4752
Reputation: 23
Adding on to @BSD's solution:
IAM role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "apigateway.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"appsync:GraphQL"
],
"Resource": [
"arn:aws:appsync:us-east-1:{AWS-Account-Number}:apis/{AppSync-API-ID}/*"
],
"Effect": "Allow"
}
]
}
The format for sending query/mutation through APIGW: Let's say your AppSync query is:
query MyQuery {
foo(request: {bar: "abc123", baz: "xyz"}) {
a
b
c
}
}
This query turns into the following JSON:
{
"query": "query MyQuery {foo(request: {bar: \"abc123\", baz: \"xyz\"}) {a b c} }"
}
Upvotes: 1
Reputation: 31
In case someone using OpenAPI spec for defining APIGW, use the following:
/graphql:
post:
x-amazon-apigateway-integration:
type: "AWS"
httpMethod: "POST"
uri: arn:aws:apigateway:<APIGW_REGION>:<APPSYNC_URL_ID>.appsync-api:path/graphql
credentials: <INVOCATION_ROLE_ARN>
https://docs.aws.amazon.com/general/latest/gr/appsync.html#appsync_region_data_plane https://docs.aws.amazon.com/apigateway/api-reference/resource/integration/#type
Upvotes: 2
Reputation: 71
I found out how to integrate appsync to API gateway. You can do it with AWS Service integration by setting it as AppSync Data Plane.
In the method setup page:
Integration type = AWS Service
AWS Service = AppSync Data Plane
AWS Subdomain = get it from your appsync endpoint (For example: https://YOUR_AWS_Subdomain.appsync-api.your-region.amazonaws.com/graphql)
HTTP method = POST
Action Type = Use path override
Path override(optional) = graphql
It worked well for me.
Upvotes: 2