How to allow invoking an AWS Lambda function only from EC2 instances inside a VPC

人走茶凉 提交于 2020-01-15 06:50:09

问题


I am struggling with understanding how I can easily invoke my lambda function from an EC2 instance within a VPC.

I think I have a quite common problem but strangely enough I didn't found anything specific for this "pattern".

I have a Python application in an EC2 instance and I would like to launch heavy processing functions in parallel using Lambda functions and keep the EC2 quite light-weight.

Ideally, the Lambda function could be invoked only from within the VPC (only from my EC2 instances).

My understanding is that I have to create an API gateway (or add an API endpoint to the Lambda function) but I don't understand how to invoke this function from the EC2 (I am trying to use HTTP requests without success) nor how to set permissions.

I used a trigger in the function to set-up the API gateway and I am using the corresponding link for requests.


回答1:


There are various ways, other than API Gateway, to invoke Lambda functions. The one most relevant to your use case would be the Invoke API. You can find the official documentation here and the Boto library's, in case you are using Boto, here.

Also, as mentioned in a comment on the question, you can assign an IAM role to the EC2 instances that allows them to Invoke the Lambda function.



来源:https://stackoverflow.com/questions/43257091/how-to-allow-invoking-an-aws-lambda-function-only-from-ec2-instances-inside-a-vp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!