AWS Lambda unable to access EC2 port within the sa

2019-07-28 00:41发布

问题:

I have a lambda function accessing Elasticsearch running on an EC2 instance in the same VPC. Unfortunately, the lambda fails to access the port even when I make it publicly accessible.

Both lambda and EC2 are assigned to the same VPC. The lambda is also assigned to a security group to which the SG assigned to EC2 explicitly gives inbound permissions. Lambda function is also assigned to a role with the following managed policies:

  • AWSLambdaExecute
  • AWSLambdaVPCAccessExecutionRole
  • CloudWatchLogsFullAccess

Is Lambda missing some permissions?

Thanks!

回答1:

The IAM Roles assigned to the Lambda function would have no bearing on this issue.

It sounds like you have setup the VPC and Security Groups correctly. How are you referencing the EC2 server from the Lambda function? You have to reference it via the private IP address assigned to the EC2 instance in order for the network traffic to stay within the VPC, and in order for the Security Group rule you have configured to apply correctly.