简体   繁体   English

通过 AWS Lambda 函数访问 EC2 实例服务

[英]Access EC2 Instance Service Via AWS Lambda Function

I have a EC2 Instance which only have Private IP and I have installed the Apache Kafka on same Instance running on say 10.0.4.44:9092 .我有一个只有私有 IP 的 EC2 实例,并且我已经在10.0.4.44:9092上运行的同一个实例上安装了 Apache Kafka。 Now, I have created the AWS Lambda Function which read the document from given Bucket and sent the Document body to Apache Kafka running on EC2 Instance.现在,我创建了 AWS Lambda 函数,它从给定的 Bucket 读取文档并将文档正文发送到在 EC2 实例上运行的 Apache Kafka。

Now, AWS Lambda is unable to access the EC2 Instance Service.现在,AWS Lambda 无法访问 EC2 实例服务。

How Can I grant access to Lambda for accessing Apache kafka Service on EC2?如何授予 Lambda 访问权限以访问 EC2 上的 Apache kafka 服务?

You need to add the Lambda function to the VPC the EC2 server is running in. Here's the announcement blog post of Lambda VPC support with a walk through for setting it up.您需要将 Lambda 函数添​​加到运行 EC2 服务器的 VPC。这是 Lambda VPC 支持的公告博客文章,其中包含设置步骤。 Here's the official documentation .这是官方文档

A Lambda function in a VPC will not get a public IP address. VPC 中的 Lambda 函数不会获得公共 IP 地址。 This means it won't be able to access anything that is outside the VPC.这意味着它将无法访问 VPC 之外的任何内容。 Since you also need to access S3 you will need to setup an S3 VPC Endpoint so that your function will still have S3 access.由于您还需要访问 S3,因此您需要设置一个 S3 VPC 端点,以便您的函数仍然可以访问 S3。

If your function needs access to other things outside the VPC then you will have to add it to a private subnet of the VPC with a NAT Gateway attached.如果您的函数需要访问 VPC 之外的其他事物,那么您必须将其添加到连接了 NAT 网关的 VPC 的私有子网中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM