简体   繁体   English

AWS Lambda函数从S3读取并写入Elastic Cache

[英]AWS Lambda function to read from S3 and write to Elastic Cache

I have to two separate Lambda functions - one to read a file from a S3 bucket and write to memcache cluster. 我必须使用两个单独的Lambda函数-一个函数从S3存储桶中读取文件并写入memcache集群。 They work well individually. 他们各自工作良好。 However, I am unable to 'merge' them together. 但是,我无法将它们“合并”在一起。

Firstly, the function to read from S3 works from 'No VPC' setting whereas, the function to write to Elastic Cache works only when the function and cluster are in the same VPC. 首先,从S3读取的功能在“无VPC”设置下起作用,而仅当该功能和群集位于同一VPC时,才能写入Elastic Cache的功能。

Secondly, the function to read from S3 had only the AmazonS3FullAccess policy applied. 其次,从S3读取的功能仅应用了AmazonS3FullAccess策略。 While I have now applied the AWSLambdaVPCAccessExecutionRole also, I am not sure, if this setting will work because of the VPC difference mentioned above. 虽然我现在还应用了AWSLambdaVPCAccessExecutionRole ,但是由于上述VPC的不同,我不确定此设置是否可以使用。

Is AWS Step function the answer? AWS Step函数是答案吗? How do I build a serverless application that reads a file from S3 and writes to Elastic Cache cluster? 如何构建无服务器应用程序,该应用程序从S3读取文件并写入Elastic Cache集群?

You don't need step functions for this. 为此,您不需要步进功能。 Run the function in the VPC with your ElastiCache cluster. 使用您的ElastiCache群集在VPC中运行该功能。 Either add an S3 endpoint to your VPC, or a NAT gateway. 将S3端点添加到您的VPC或NAT网关。 The S3 endpoint is the easiest solution. S3端点是最简单的解决方案。 Then your function will have access to both ElastiCache and S3. 然后,您的函数将可以访问ElastiCache和S3。

For the IAM role, you need to go into IAM and create a new role that has the permissions of AWSLambdaVPCAccessExecutionRole as well as the necessary S3 permissions. 对于IAM角色,您需要进入IAM并创建一个具有AWSLambdaVPCAccessExecutionRole权限以及必要的S3权限的新角色。 You can assign multiple policies to a single role if necessary. 您可以根据需要将多个策略分配给一个角色。 Then assign that role to the Lambda function. 然后将该角色分配给Lambda函数。

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

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