amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

API Gateway - Customise DEFAULT_5XX gateway response

Open dtmorgan opened this issue 11 months ago • 1 comments

Amplify CLI Version

12.12.4

Question

I would like to customise the response template for DEFAULT_5XX gateway response (see image below).

Screenshot 2024-11-14 at 11 12 23 AM

I tried to override the API in my Amplify project by using the code following code but always fail to build the project.

export function override(
  resources: AmplifyApiRestResourceStackTemplate,
  amplifyProjectInfo: AmplifyProjectInfo
) {
  new CfnGatewayResponse(resources.restApi.stack, 'MyGatewayResponse', {
    restApiId: resources.restApi.ref,
    responseType: 'DEFAULT_5XX',
    statusCode: '500',
    responseTemplates: {
      'application/json': JSON.stringify({ message: 'Internal Error' }),
    },
  });
}

dtmorgan avatar Nov 14 '24 03:11 dtmorgan