How to use AWS Elasticache from Lambda in c#

给你一囗甜甜゛ 提交于 2019-12-11 05:55:58

问题


I've searched and searched and have been unable to find a tutorial / example / walkthrough with all of the above! I am trying to write a Lambda function in C# which makes use of some ElastiCache storage. I can find examples of ElastiCache access from C#, but every Library I have found referenced will not operate with .NetCore 1.0, which is what Lambda uses! Has anyone managed to do this? Many thanks.


回答1:


Yes, it is possible and you're right, the information on this subject is sparse. The key is to host your Elasticache instance and Lambda Function in the same VPC. From a high level you need to:

  1. Setup a VPC with at least two subnet groups, a route table, and a security group.
  2. Create an Elasticache Subnet Group pointing to the two subnet groups created in step 1.
  3. Create your Elasticache instance with it pointed to the Elasticache Subnet Group created in step 2.
  4. Create your C# Lambda function and use a 3rd party library to connect to Elasticache. For Redis, I used StackExchange.Redis 1.2.1 successfully with .Net Core 1.0. More recent versions will not work with .Net Core 1.0.
  5. Associate your Lambda with the same VPC, subnets, and security group.
  6. Associate your Lambda function with an IAM Role that allows you to execute the Lambda and call ec2:CreateNetworkInterface (I think it is needed for the VPC call, but not sure). Something like AWSLambdaFullAccess and AWSLambdaVPCAccessExecutionRole will work.
  7. Test your Lambda for connectivity.

This blog posting has a better walkthrough: http://fitsofury.blogspot.com/2018/02/aws-connect-to-elasticache-redis.html



来源:https://stackoverflow.com/questions/44741141/how-to-use-aws-elasticache-from-lambda-in-c-sharp

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