Configuring Lambda Function For Custom Domain By Using API Gateway

Arnob
3 min readDec 3, 2023

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

Create Lambda Function

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

Here the function

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

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

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

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

Then at Configuration > Triggers, a API Gateway came.

You can visit the link

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

Click Request a Certificate

Click Next

Then you see the Certificates list. Click on the id

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

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

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

Add API Gateway

Now add a custom Domain Names

Create a Domain

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

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

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

Custom Domain Mapping Done.

--

--