Search code examples
amazon-web-servicesaws-lambdaamazon-elbaws-application-load-balancerelastic-ip

Call AWS Lambda function via public IP address


I am building a webserver with AWS Lambda and I need a public IP address that I can call to request the Lambda function. My users need to put this IP address as an A record into their DNS.

Is it somehow possible, for example, to associate an Elastic IP to a single Lambda function for incoming traffic? Maybe through a load balancer?

For the outgoing traffic I have my NAT and Internet Gateways, which are working fine.


Solution

  • You have 2 choices that can provide this functionality:

    • API Gateway - This is made for traditional API calls, you will need to create a custom domain mapping to your API within AWS for each domain that will use the API Gateway.
    • Application Load Balancer - You can use an ALB to have your Lambda as a target for all requests. However, without path based pattern matching be aware that all requests will arrive at the same Lambda.

    Both of the above will require that the subdomain is mapped by a CNAME rather than an A Record. This is because both of these domains recycle IP addresses on an infrequent basis.

    If you absolutely must have the record resolve to an IP you would need to use an NLB in front of you ALB. The NLB supports a static IP per subnet, the ALB would then become its target through IP mapping and an existing AWS service. If you can use CNAMEs then you do not need to do this.