API Gateway

Common Errors

Works in Lambda, but not in API Gateway

Testing in API Gateway:
Status: 502
Response Body:
1
{
2
"message": "Internal server error"
3
}
Copied!
Logs:
Lambda execution failed with status 200 due to customer function error: RequestId: 80572150-944e-40e5-b782-aca7f713289f Process exited before completing request. Lambda request id: 80572150-944e-40e5-b782-aca7f713289f

Solution

Check your lambda function is either:
  • Make sure you define your handler function async ; or
  • Use the callback argument in your handler
For example:
1
export async function webhook(event, context) {
2
return {
3
statusCode: 200,
4
};
5
}
Copied!
or
1
export function webhook(event, context, callback) {
2
callback(null, { statusCode: 200 });
3
}
Copied!

Using Custom Domains with Cloudflare

  1. 1.
    Open AWS ACM Console (us-east-1)
    1. 1.
      Click "Request a Certificate"
    2. 2.
      Enter the domains you want to enable
  2. 2.
    Open AWS API Gateway​
    1. 1.
      Select "Custom Domain Names" from the left menu.
    2. 2.
      Click the "Create Custom Domain Name" button.
    3. 3.
      Enter the "Domain Name"
    4. 4.
      Select the ACM Certificate (us-east-1)
    5. 5.
      Click "Base Path Mappings"
      1. 1.
        Set the relevant path and destination
    6. 6.
      Hit "Save"
    7. 7.
      Wait a maximum of 40 minutes
  3. 3.
    Open Cloudflare​
    1. 1.
      Select your domain and open the "DNS" tab
    2. 2.
      Add a CNAME record
      1. 1.
        For "Name":
        1. 1.
          Use "@" if you are targeting the root domain. For example "build.my"
        2. 2.
          Use "www" if you are targetting a subdomain. For example: "www.build.my"
      2. 2.
        For "Domain name":
        1. 1.
          Use the AWS APIGateway Target Domain Name. For example: "d1jdvkqtea2e81.cloudfront.net"
      3. 3.
        For Status:
        1. 1.
          Set to: DNS Only
Test only on https . Testing on http will redirect to https so it looks like nothing is happening.
1
curl --verbose https://dt.cards/
Copied!
Pieced from:
​
Last modified 2yr ago