Is there a way to assign a Static IP to a AWS Lambda without VPC?

后端 未结 4 673
说谎
说谎 2021-02-08 14:42

I am looking to assign a static IP to my Lambda which is being invoked via the API gateway. This is required because, the downstream system that i invoke from this lambda accept

相关标签:
4条回答
  • 2021-02-08 15:27

    I agree with the answer by John for having static IP whitelisting part. However, it won't resolve your cold start problem because lambda,if ideal, actually takes a small time to start. So I would recommend you also create a Cloudwatch event to hit lambda periodically to resolve this or write a simple code(either in lambda or somewhere else) which sends an empty request periodically so that cold start problem is resolved. You can view the improvement in X-Ray. This is an overhead but one time process.

    0 讨论(0)
  • 2021-02-08 15:34

    You can't assign a public/static IP to any Lambda function.

    Your only good option is to deploy into a VPC with an Internet Gateway and configure routing from the Lambda's subnet through a NAT which has an Elastic IP. Then your target host can whitelist the Elastic IP.

    Also see:

    • Public IP address for AWS API Gateway & Lambda (no VPC) - Stack Overflow
    • AWS Lambda functions with a static IP – Matthew Leak – Medium
    0 讨论(0)
  • 2021-02-08 15:36

    You will need to:

    • Create a VPC with an Internet Gateway, a public subnet and a private subnet
    • Attach the AWS Lambda function to the private subnet
    • Launch a NAT Gateway in the public subnet and update the Route Table of the private subnet to use the NAT Gateway

    The NAT Gateway will use an Elastic IP address (which is a static IP address). All traffic from the Lambda function to the Internet will come from this IP address, which can be used in the whitelist.

    You might think that this is a bit of overkill for simply attaching a static IP address, but multiple Lambda function can run in parallel and they could run in multiple Availability Zones. Sending all traffic through the NAT Gateway is the only way to ensure they all have the same IP address. (Or, to be more specific, one IP address per AZ in which the NAT Gateway is launched.)

    0 讨论(0)
  • 2021-02-08 15:38

    The way to assign a static IP address without a VPC is AWS Network balancer.

    0 讨论(0)
提交回复
热议问题