I'm using serverless to create a lambda function using the nodejs template.
我正在使用serverless创建一个lambda函数,使用nodejs模板。
- To connect to my Elasticache Redis I setup a VPC and added the Security Group and Subnet Ids, as well as the region to my lambda
serverless.yml
. - 为了连接到我的elastic Redis,我设置了一个VPC,并添加了安全组和子网id,以及这个区域到我的lambda server .yml。
- I deployed it and confirmed I could set and get a key from Redis.
- 我部署了它并确认我可以设置并从Redis获得一个密钥。
When I try to serverless invoke local -f functionName
, it always times out, so I have to deploy it to test it.
当我尝试不使用服务器调用本地-f函数名时,它总是超时,所以我必须部署它来测试它。
Is it possible to test this out locally with serverless
?
是否可以使用无服务器的本地测试?
1 个解决方案
#1
4
Elasticache is not directly accessible from outside AWS environment by default. According to their documentation, the service is designed to be accessed exclusively from within AWS. In your case, serverless invoke local
times out because the connection itself cannot be established and the lambda function times out. So you can't run invoke locally to test this connection the way you are trying to do.
在默认情况下,从外部AWS环境中不能直接访问到弹性。根据他们的文档,该服务被设计为仅从AWS内部访问。在您的示例中,serverless调用本地时间,因为连接本身无法建立,lambda函数超时。因此,您不能以您正在尝试的方式在本地运行invoke来测试此连接。
To connect to Elasticache redis from your local machine, you can use a NAT instance in your public subnet and setup the security groups to open up the correct ports and enable IP forwarding to allow connection to your redis cache cluster. The steps are given here.
要从本地机器连接到elastic redis,您可以在公共子网中使用一个NAT实例,并设置安全组来打开正确的端口,并允许IP转发连接到redis缓存集群。这里给出了步骤。
However, I would just install redis locally and use an environment variable to change the connection string to connect to local redis on local machine and the actual Elasticache cluster when running on lambda.
但是,我只需要在本地安装redis,并使用一个环境变量来更改连接字符串,以便在本地机器上连接到本地redis,以及在lambda上运行时实际的橡筋簇。
#1
4
Elasticache is not directly accessible from outside AWS environment by default. According to their documentation, the service is designed to be accessed exclusively from within AWS. In your case, serverless invoke local
times out because the connection itself cannot be established and the lambda function times out. So you can't run invoke locally to test this connection the way you are trying to do.
在默认情况下,从外部AWS环境中不能直接访问到弹性。根据他们的文档,该服务被设计为仅从AWS内部访问。在您的示例中,serverless调用本地时间,因为连接本身无法建立,lambda函数超时。因此,您不能以您正在尝试的方式在本地运行invoke来测试此连接。
To connect to Elasticache redis from your local machine, you can use a NAT instance in your public subnet and setup the security groups to open up the correct ports and enable IP forwarding to allow connection to your redis cache cluster. The steps are given here.
要从本地机器连接到elastic redis,您可以在公共子网中使用一个NAT实例,并设置安全组来打开正确的端口,并允许IP转发连接到redis缓存集群。这里给出了步骤。
However, I would just install redis locally and use an environment variable to change the connection string to connect to local redis on local machine and the actual Elasticache cluster when running on lambda.
但是,我只需要在本地安装redis,并使用一个环境变量来更改连接字符串,以便在本地机器上连接到本地redis,以及在lambda上运行时实际的橡筋簇。