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개 답변
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...

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠