从AWS Lambda连接Cassandra [英] Connecting Cassandra from AWS Lambda

查看:59
本文介绍了从AWS Lambda连接Cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在检查将我们的应用程序之一迁移到Amazon Web Services(AWS)的可行性.我们决定使用AWS API Gateway公开服务,并使用AWS Lambda(java)进行后端数据处理.lambda函数必须从我们的数据库中获取大量数据.当前使用Cassandra进行数据存储,该存储已在EC2实例中设置,并且没有公共IP.

We are checking the feasibility of migrating one of our application to Amazon Web Services (AWS) . We decide to use AWS API Gateway to expose the services and AWS Lambda (java) for back end data processing. The lambda function has to fetch a large amount of data from our database. Currently using Cassandra for data storage, which has been set up with in an EC2 instance and it has no public ip.

有人可以建议一种使用私有Ip(10.0.x.x)从AWS Lambda访问Cassandra(EC2)的方法吗?

Can anyone suggest a way to access Cassandra(EC2) from AWS Lambda using the private Ip ( 10.0.x.x)?

将AWS Lambda用于大型应用程序是正确的选择吗?

Is it a right choice to use AWS Lambda for large scale applications?

推荐答案

由于您的Cassandra实例正在使用私有IP,因此您需要将AWS lambda网络配置为使用VPC.可能是您在其中运行Cassandra的VPC,也可能是您为创建lambda而创建的VPC,并且您的VPC与cassandra VPC对等.文档中应注意的几点:

Since your Cassandra instance is using private IP, you will need to configure your AWS lambda Network to use a VPC. It could be the VPC you are running Cassandra in, or a VPC you create for the purpose of your lambdas, and that you VPC-peer to your cassandra VPC. A few things to note from the documentation :

  • 当您的lambda在VPC中运行时,默认情况下它没有Internet访问权限,因此您需要为此配置 NAT .
  • ENI 的配置会导致额外的延迟(您只需在冷启动时支付该罚款)
  • 您需要确保您的lambda拥有管理ENI的正确权限,您应该使用以下角色: AWSLambdaVPCAccessExecutionRole
  • when your lambda runs in a VPC, it doesn't have internet access by default, you will need to configure a NAT for that.
  • There is an additional latency due to the configuration of the ENI (you only pay that penalty on cold start)
  • You need to make sure your lambda has the right permission to manage the ENI, you should use this role: AWSLambdaVPCAccessExecutionRole

您打算使用API​​/AWS lambda的计划至少有3个潜在问题,您需要仔细考虑:

Your plan to use API / AWS lambda has at least 3 potential issues which you need to consider carefully:

  • 费用.每个请求成本的API网关高于每个请求成本的AWS lambda.确保您熟悉费用.
  • 冷启动.当AWS启动基础容器来执行lambda时,您将付出冷启动延迟(由于使用ENI的管理,在使用VPC时会变得更糟).如果同时执行lambda,将有多个基础容器.他们每个人都会在第一次冷启动.AWS倾向于在几分钟内使基础容器为热启动做好准备(用户报告5到40分钟).您可以通过ping aws lambda来尝试使容器保暖,显然,如果您并行使用多个容器,则会变得很棘手.
  • Cassandra会话.您可能希望避免每次调用Lambda时都创建和销毁Cassandra会话(代价高昂).我还没有尝试过,但是有报告说可以在温暖的容器中保持会话的正常运行,您可能要检查此 SO答案.
  • Cost. API gateway per request cost is higher than AWS lambda per request cost. Make sure you are familiar with the cost.
  • cold start. When AWS start an underlying container to execute your lambda, you pay a cold start latency (which get worse when using VPC due to the management of the ENI). If you execute your lambda concurrently, there will be multiple underlying containers. Each of them will have this cold start the first time. AWS tends to keep the underlying containers ready for a warm start, for a few minutes (users report 5 to 40 minutes). You might try to keep your container warm by pinging your aws lambda, obviously if you have multiple container in parallel, it is getting tricky.
  • Cassandra session. You will probably want to avoid creating and destroying your Cassandra session each time you invoke your lambda (costly). I haven't tried yet, but there are reports of keeping the session alive in a warm container, you might want to check this SO answer.

话虽如此,当前使用AWS Lambda的最大限制是并发执行和冷启动延迟.对于数据处理,通常没问题.对于面向用户的使用,缓慢启动的百分比可能会影响您的用户体验.

Having say all that, currently the biggest limitation in using AWS lambda is concurrent execution and cold start latency. For data processing, that's usually fine. For user-facing usage, the percentage of slow cold start might affect your user experience.

这篇关于从AWS Lambda连接Cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆