Unable to access AWS SimpleDB from VPC enabled Lambda - amazon-web-services

I am facing a problem to access SimpleDB database from my VPC enabled Lambda function.
Below are the things which I have already done for VPC enabled lambda :
1. I have already set up my VPC configuration which includes NAT Gateway setting,Public and Private subnet and also Security Group and also created elastic IP for the same.
2. I have already tested my VPC enabled lambda by calling third party API to check internet access to my VPC enabled lambda and it is working fine.
3. I have also added SimpleDB permission policies for my VPC enabled Lambda role.
4. Also, I checked SimpleDB connection in lambda code without VPC and it is working fine.
But when I am trying to access SimpleDB with VPC enabled, it is resulting into timeout error.
Can anyone please help me out on this ?

Related

how to connect a lambda function (behind an api gateway) to a private rds in a vpc

I have the following AWS VPC configuration:
2 public subnets
2 private subnets
Cloudfront is in front of the load balancer. The load balancer is linked to the public subnets and my RDS database reside in the private subnets.
What i want to accomplish is:
Create an API Gateway (publicly accessible) but restricted to only a specific IP address that can access it. The API Gateway is connected to a lambda function that, when called/triggered, the function must update some table data of my (private) RDS Postgres instance.
From my understanding the first step would be to create an IAM role for the lambda function to be only accessible by the IP address mentioned above.
Now what is the best way to access a private RDS from that lambda connected to API Gateway? Especially without using Nat Gateway because of the crazy cost associated to it.
Can someone help me just figure out how to do it, i am referring to the high level understanding how to do it?
As Norman said in their comment, you can control access to your API in API Gateway, and limit it to certain IP addresses, with API Gateway Resource Policies. This will at the same time control access to your Lambda that's behind that API.
You can then edit the Lambdas Configuration -> VPC setting and add it to a subnet that has access to your RDS database (and put it either in the same subnet as the database, or another subnet that has access permissions to the RDS subnet). To connect your Lambda to a VPC, the Lambda execution role will need the following permissions
ec2:CreateNetworkInterface
ec2:DescribeNetworkInterfaces
ec2:DeleteNetworkInterface
They are for example included in the managed policy AWSLambdaVPCAccessExecutionRole. Here you can read more about configuring a Lambda for VPC access.

How do I create an AWS VPC Endpoint for Elasticsearch?

I have a lambda function which must be placed in a VPC because it communicates over a VPC peering connection. I also need it to upload to my Elasticsearch Service domain (not in a VPC because it is publicly accessible). But currently when Lambda tries to talk to ES, it times out.
I ran into this problem with Secrets Manager, so I went into the lambda's VPC, clicked on Endpoints, and created a Secrets Manager endpoint. I would like to do the same with Elasticsearch Service, but it doesn't show up in my list of AWS Services, which is odd because it definitely is an AWS Service.
Any idea how I can add an endpoint for Elasticsearch Service in my VPC so my Lambda function can talk to it? Thanks!
There is no VPC endpoint for ES. The services that support the endpoints are listed here.
Regarding the timeout, you would have to provided detailed description of your VPC setup, subnets, route tables, lambda and explain how did you setup your ES and how do you try to access it from VPC. Its difficult to speculate why it times out without all the details.
But since your ES is public, one possibility could be because lambda in VPC will not be able to connect to it without the use of NAT gateway. By default, lambda in a VPC does not have internet connectivity.

AWS Lambda Function Timeout on Connecting To RDS Database through RDS Proxy

I'm trying to test AWS RDS proxy so I created a lambda function and done all steps that are present in this official link
https://aws.amazon.com/blogs/compute/using-amazon-rds-proxy-with-aws-lambda
store RDS credentials in Secret Manager
create new role and also add Trust Policy
in lambda function, from the AWS console, add proxy and its status is available.
When I execute the lambda function, it times out with no errors it seems like the error might be on connecting to db with rds proxy because when I run the lambda function again without proxy, it works just fine.
I initially thought that it might be a security group issue, so I edit the security group of RDS Proxy and update inbound and allow 0.0.0.0 (outbound was already 0.0.0.0).
I used defaut VPC in RDS Database and RDS Proxy. The endpoint of RDS database is public.
Since RDS proxy is not available outside the VPC. Configure your lambda function to run inside the VPC. The following link will help:
https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html
Late answer.. thought these might help others.
You have to keep your lambdas inside the same VPC and subnets to access RDS proxy.
In any case if you want to access third party web api from your lambda, you have make the lambda subnets private (no Internet Gateway in route table) and assign a NAT gateway which is tied with a public subnet.
If you are accessing other AWS services which are out of VPC like S3, Secret Manager etc. then you have to create VPC endpoints for those services in your VPC.

How to debug connection issue: Connecting to SSM VPC Endpoint from Lambda Function in VPC

I have a lambda function in a VPC that should be able to connect to SSM via a VPC endpoint. In fact, I have had this working in another VPC (the default), but just can't get it to work in a new VPC that I have built with CloudFormation. In addition, I am able to connect to S3 via a VPC endpoint for the same VPC:
The subnets that Lambda is being deployed in, are associated with the SSM VPC Endpoint.
The VPC endpoint is associated with a security group that accepts incoming requests on port 443 from the application layer security group (which is associated with the lambda function).
The Lambda function's application layer security group has an outgoing rule that allows it to broadcast anywhere 0.0.0.0/0
The NACL for the subnets allows all incoming and outgoing traffic.
The lambda function's role has permission to execute all SSM actions on all resources (just a temporary situation to rule out iam permissions)
I have tried console.log debugging, and it shows the lambda function timing out after it tries to get info from SSM.
I have tried using flow logs, but I can see no connections, or any data flowing to and from SSM.
I have compared the 2 VPC's (the one in which it works and the one in which it doesn't) and I can't see any differences in rules.
Can anyone suggest how I might debug this?
Thanks
Finally found the issue and thought I'd post this just in case anyone else has the same issue.
The VPC Endpoints needed to have private dns enabled.
When creating the VPC endpoint manually via the console, the Enable Private DNS Name checkbox is checked by default.
However, when creating the VPC endpoint using CloudFormation, the PrivateDnsEnabled property needs to be explicitly set to true.

AWS cross region lambda database access

Recently some service in us-west-1 seems not working, so I'm trying to create a lambda that can access cross-region RDS (from us-east-1 to us-west-1), but I cannot find any solution or sample with these keywords. Does that means cross-region database is unavailable?
As I know, use lambda reach to database in VPC may cause out of IP issues, so is there any best practice for this?
Thanks
Lambda functions run outside the VPC by default. In the setup of the Lambda you can opt to give them access to a VPC which creates a network endpoint inside your VPC. Lambda uses that network endpoint to access the VPC.
The challenge you face is that your us-west-1 VPC is not visible in us-east-1.
Suggestion: Setup VPC peering between the two VPCs and run the lambda in the us-east-1 VPC.