简体   繁体   English

Amazon Lambda Node.js Elasticache在Redis中存储数据

[英]Amazon lambda nodejs elasticache store data in redis

I have a lambda function(runtime: Nodejs 4.3) and I need to store data in elasticache. 我有一个lambda函数(运行时:Node.js 4.3),我需要将数据存储在elasticache中。 The engine is redis. 引擎是redis。 This is my function: 这是我的功能:

const redis = require("redis");
exports.handler = function (event, context, callback) {
    callback(null, {});
};

Lambda returns "errorMessage": "Cannot find module 'redis'", error. Lambda返回"errorMessage": "Cannot find module 'redis'",错误。 Should I add nom redis package in zip? 我应该在zip中添加nom redis软件包吗?

All npm modules needs to be installed in node_modules folder. 所有npm模块都需要安装在node_modules文件夹中。 You can use npm install --save package name command to install node_module and save its name in package.json. 您可以使用npm install --save package name命令安装node_module并将其名称保存在package.json中。 Refer this link for --save option explanation . 请参考此链接以获取--save选项说明

Zip the index.js and node_moule for upload. 压缩index.js和node_moule以进行上传。 index.js file is your handler function, if your handler name is different, use that name for js file and zip file. index.js文件是您的处理程序函数,如果您的处理程序名称不同,请将该名称用于js文件和zip文件。

Note:- It is best to use node-lambda module for developing your code on local ec2 machine. 注意:-最好使用node-lambda模块在本地ec2机器上开发代码。 Execute it with the node-lambda run and use node-lambda deploy for deploying the code over lambda. 通过运行node-lambda来执行它,并使用node-lambda deploy在lambda上部署代码。 Zipping and all other things will be taken care by node-lambda. node-lambda将负责压缩和其他所有操作。

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

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