Can't Connect API Gateway to Appsync GraphQL Endpoint - 500 Errors

0

I'm Trying to make an API Gateway path that will proxy to my Appsync GraphQL API. This is so that users can access it at our normal domain instead of the subdomain Appsync gives us. All settings appear to be correct but it's throwing 500 errors when I attempt to use it and there are no logs in API Gateway or Appsync that explain why it's throwing 500 errors. Appsync works fine when calling it directly via the given subdomain. API Gateway also works fine for the other endpoints. I'm using CDK to setup all services. My setup code is below:

const api = new RestApi(this, 'poolsApi', {
      restApiName: 'Pools Service',
      deployOptions: {
        accessLogDestination: new LogGroupLogDestination(apiGatewayLogGroup),
        accessLogFormat: AccessLogFormat.jsonWithStandardFields({
          caller: false,
          httpMethod: true,
          ip: false,
          protocol: true,
          requestTime: true,
          resourcePath: true,
          responseLength: true,
          status: true,
          user: false
        }),
        cachingEnabled: true,
        cacheClusterEnabled: true
      }
    });

const graphqlApi = new GraphqlApi(this, 'Api', {
      name: 'poolsApi',
      schema: Schema.fromAsset(join(__dirname, 'appsync/pools/schema.graphql')),
      authorizationConfig: {
        defaultAuthorization: {
          authorizationType: AuthorizationType.API_KEY,
          apiKeyConfig: {
            name: 'BalancerAPIKey',
            expires: Expiration.atTimestamp(BALANCER_API_KEY_EXPIRATION),
          },
        },
      },
      xrayEnabled: true,
    });

const graphQLApiEndpoint = api.root.addResource('graphql');
graphQLApiEndpoint.addMethod('POST', new AwsIntegration({
      service: 'appsync-api',
      region: this.region,
      subdomain: graphqlApi.apiId,
      integrationHttpMethod: 'POST',
      path: 'graphql',
      options: {
        passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
        credentialsRole: appSyncAccessRole,
        integrationResponses: [{
          statusCode: '200'
        }],
        requestParameters: {
          'integration.request.header.x-api-key': `'${graphqlApi.apiKey}'`
        }
      },
    }), {  
      methodResponses: [{
        statusCode: '200',
        responseModels: {
          'application/json': Model.EMPTY_MODEL
        }
      }]
   });
   addCorsOptions(graphQLApiEndpoint);


export function addCorsOptions(apiResource: IResource) {
  apiResource.addMethod(
    'OPTIONS',
    new MockIntegration({
      integrationResponses: [
        {
          statusCode: '200',
          responseParameters: {
            'method.response.header.Access-Control-Allow-Headers':
              "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'",
            'method.response.header.Access-Control-Allow-Origin': "'*'",
            'method.response.header.Access-Control-Allow-Credentials':
              "'false'",
            'method.response.header.Access-Control-Allow-Methods':
              "'OPTIONS,GET,PUT,POST,DELETE'",
          },
        },
      ],
      passthroughBehavior: PassthroughBehavior.NEVER,
      requestTemplates: {
        'application/json': '{"statusCode": 200}',
      },
    }),
    {
      methodResponses: [
        {
          statusCode: '200',
          responseParameters: {
            'method.response.header.Access-Control-Allow-Headers': true,
            'method.response.header.Access-Control-Allow-Methods': true,
            'method.response.header.Access-Control-Allow-Credentials': true,
            'method.response.header.Access-Control-Allow-Origin': true,
          },
        },
      ],
    }
  );
}
1 Resposta
0

I couldn't get the AwsIntegration working and switched to a HttpIntegration instead. There are no docs explaining the AwsIntegration and how it works anywhere on AWS...

respondido há um ano

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas