DEV Community

Arnob
Arnob

Posted on

Configuring Lambda Function For Custom Domain By Using API Gateway

Here Configuring a custom domain for AWS Lambda Function with API Gateway.

captionless image

Create Lambda Function

At first create a lambda function. Here i just create a normal hello-world function.

captionless image

Here the function

export const handler = async (event) => {
  // TODO implement
  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};
Enter fullscreen mode Exit fullscreen mode

This is the hello world function. Now this function need to connect custom domain.

Create API Gateway

Go to Lambda function add a API Gateway

captionless image

After clicking the add trigger button, Search API Gateway. Select that

captionless image

At Intent, Select Create a new API and Security is open, Then click Add Button.

captionless image

Then at Configuration > Triggers, a API Gateway came.

captionless image

You can visit the link

captionless image

Here the API Gateway creating is Done. Now need to add custom domain.

Add Custom Domain

If you don’t mapping with Cloudflare and AWS Certificate Manager . Then you have to map it 1st.

AWS Certificate Manager

captionless image

Click Request a Certificate

captionless image

Click Next

captionless image

Then you see the Certificates list. Click on the id

captionless image

Note: This Domain Already Issued. I just show to process.

captionless image

Then copy the CNAME Name and CNAME Value. Then add to the cloudflare dns record

captionless image

After add the record. Wait 5 min, it will be issued.

Add API Gateway

Now add a custom Domain Names

captionless image

Create a Domain

captionless image

Then Click Create Domain Name Button.

Note: It will be created. I already create this domain. So here getting the error message.

Then goto Custom Domain Names. Select the domain

captionless image

Copy the API Gateway domain name. Then goto Cloudflare. Add a record

captionless image

Done. Now wait for 5 min. It will sync the DNS Record.

captionless image

Custom Domain Mapping Done.

Top comments (0)