我在s3(公共)上有一些证书文件,我将在我的代码中下载并使用这些文件.如果我在本地的nodejs中编写一个等效代码,它运行正常,但在AWS lambda中它只是崩溃了.
var apn = require('apn');
var https = require('https');
var fs = require('fs');
exports.handler = function(event, context) {
console.log("Running aws apn push message function");
console.log("==================================");
console.log("event", event);
var certPath = event.certPath;
var keyPath = event.keyPath;
var certFileName = event.certFileName;
var keyFileName = event.keyFileName;
var passphrase = event.passphrase;
var apnId = event.apnId;
var content = event.content;
var certfile = fs.createWriteStream(certFileName);
var certrequest = https.get(certPath, function(certresponse) {
certresponse.pipe(certfile);
console.log("downloaded the certificate");
var keyfile = fs.createWriteStream(keyFileName);
var keyrequest = https.get(keyPath, function(keyresponse) { …Run Code Online (Sandbox Code Playgroud) 我有一个Lambda(NodeJS)函数,可以将数据写入DynamoDB.其中一些数据需要加密.我正在使用KMS加密和存储进行加密.当我使用不同的Lambda函数从Dynamo检索并尝试解密时,我收到错误.如果我加密然后转换解密,我能够做到这一点,但如果我从数据库中读取加密值,它将无法解密.我的加密/存储代码如下:
console.log('Loading event');
var AWS = require('aws-sdk');
var keyId = "arn:aws:kms:us-east-1:5423542542:key/xxxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxx";
var tableName = "person";
var dynamoDBConfiguration = {
"region": "us-west-2"
};
AWS.config.update(dynamoDBConfiguration);
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var kms = new AWS.KMS({region: 'us-east-1'});
var newId = "1234-56789-101112-13141516";
var item = {};
exports.handler = function (event, context) {
console.log('ssn');
//encrypt it
var ssnParams = {
KeyId: keyId,
Plaintext: "123-45-6789"
};
kms.encrypt(ssnParams, function (err, data) {
if (err) {
console.log(err, err.stack);
}
else {
console.log(' ssn encrypted');
var enc_ssn = …Run Code Online (Sandbox Code Playgroud) encryption amazon-web-services node.js amazon-dynamodb aws-lambda
看一下AWS文档,
您在Pre Sign-up Lambda功能中有以下参数 :
"request": {
"userAttributes": {
"string": "string",
....
},
"validationData": {<validation data as key-value (String, String) pairs, from the client>}
Run Code Online (Sandbox Code Playgroud)
有没有办法修改或添加其他userAttributes事件对象?
例如:
// Modify an existing username...
event.request.userAttributes.name.ucfirst();
// Add an additional attribute...
event.request.userAttributes.nickname = "ANY_NAME";
callback(null, event);
Run Code Online (Sandbox Code Playgroud) 在 AWS 中,我有一个节点版本 10 上的 lambda 函数,但我想更新它run time version- 我应该运行哪个命令来实现这一点,例如想要更新runtime到版本 12?我知道已经有一篇关于AWS Lambda 函数从 NodeJs 版本 6.10 升级到 8.10 版本的文章,但我想知道如何通过命令而不是控制台来执行此操作。
我需要创建一个Zip文件,其中包含位于我的s3存储桶中的一系列文件(视频和图像).
目前使用我的代码的问题是我很快就达到了Lambda的内存限制.
async.eachLimit(files, 10, function(file, next) {
var params = {
Bucket: bucket, // bucket name
Key: file.key
};
s3.getObject(params, function(err, data) {
if (err) {
console.log('file', file.key);
console.log('get image files err',err, err.stack); // an error occurred
} else {
console.log('file', file.key);
zip.file(file.key, data.Body);
next();
}
});
},
function(err) {
if (err) {
console.log('err', err);
} else {
console.log('zip', zip);
content = zip.generateNodeStream({
type: 'nodebuffer',
streamFiles:true
});
var params = {
Bucket: bucket, // name of dest bucket
Key: 'zipped/images.zip', …Run Code Online (Sandbox Code Playgroud) 我使用nodeJS sdk将项目放到dynamoDB,该项目是:
{
"eventId": date + '-' + eventName + '-' + eventPurpose,
"eventName": eventName,
"eventPurpose": eventPurpose,
"eventDates": eventDates,
"attendees": attendees
}
Run Code Online (Sandbox Code Playgroud)
将项目放入dynamoDB的当前代码:
const params = {
TableName: "event",
Item: {
"eventId": date + '-' + eventName + '-' + eventPurpose,
"eventName": eventName,
"eventPurpose": eventPurpose,
"eventDates": eventDates,
"attendees": attendees
},
ReturnValues: "ALL_OLD"
};
dynamo.put(params, (err, data) => {
console.log("coming here");
if (err) {
console.log("error : " + JSON.stringify(err));
}
console.log("data" + JSON.stringify(data));
cb(null, data);
});
Run Code Online (Sandbox Code Playgroud)
插入正确发生,返回值是一个空对象.
我想返回插入的项目.我找到了这个文档.但只有在更新旧值时才会返回.除了这个,我找不到任何其他有用的信息.
是否有任何解决方法或者我们只需要 …
amazon-web-services node.js amazon-dynamodb aws-lambda serverless-framework
我需要一些lambda函数来获得这个流程:
触发S3 put文件事件 - > lambda函数 - >将行插入DynamoDB
当我从lambda屏幕使用AWS创建测试时,我得到了这个示例,Records列表中只有1条记录:
{
"Records": [ // <<<----------------only 1 element
{
"eventVersion": "2.0",
"eventTime": "1970-01-01T00:00:00.000Z",
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"s3": {
"configurationId": "testConfigRule",
"object": {
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901",
"key": "HappyFace.jpg",
"size": 1024
},
"bucket": {
"arn": "arn:aws:s3:::mybucket",
"name": "roeyg-oregon-s3-bucket",
"ownerIdentity": {
"principalId": "EXAMPLE"
}
},
"s3SchemaVersion": "1.0"
},
"responseElements": {
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH",
"x-amz-request-id": "EXAMPLE123456789"
},
"awsRegion": "us-east-1",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"eventSource": "aws:s3"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我尝试了几种方法来查看是否可以在此列表中获得包含多个元素的列表,例如使用CLI或将多个文件一起上传甚至整个文件夹,在所有这些场景中,我每个事件都有一个项目. …
我有一个用例,我有一个AWS Step功能,当文件上传到S3时触发,从那里第一步运行ffprobe从外部服务获取文件的持续时间,如transloadit,其中写入输出回到S3.
我可以从该事件创建一个新的step函数,但是如果可以在原始step函数中有一个Await promise然后继续到下一个函数,我就会徘徊 - 考虑到ffprobe可能需要更长的时间才能恢复.
任何建议都非常感谢如何解决这个问题.
我有一个用于向另一个端点发出 HTTP POST 请求的 AWS Lambda 函数的 Python 脚本。由于Python的urllib2.request,https://docs.python.org/2/library/urllib2.html,只能在标准处理数据application/x-www-form-urlencoded格式,我要张贴JSON数据,我使用的请求库,https://pypi.org /project/requests/2.7.0/。
该请求库在 Python 运行时环境中的 AWS Lambda 中不可用,因此必须通过from botocore.vendored import requests. 到现在为止还挺好。
今天,我收到了一个弃用警告:
DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'.
This is not a public API in botocore and will be removed in the future.
Additionally, this version of requests is out of date. We recommend you install the
requests package, 'import requests' directly, and use the requests.post() function instead. …Run Code Online (Sandbox Code Playgroud) 我希望利用ES6 附带的本机导入/导出。
我在 AWS Lambda 中使用无服务器容器。
我有我的Dockerfile看起来像这样:
FROM public.ecr.aws/lambda/nodejs:14
COPY app ./
RUN npm install
CMD [ "app.handler" ]
Run Code Online (Sandbox Code Playgroud)
然后我有一个app包含我的应用程序代码的目录。该app.js代码如下所示:
import { success } from './utils/log';
exports.handler = async () => {
success('lambda invoked');
const response = 'Hello World';
return {
statusCode: 200,
body: JSON.stringify(response),
isBase64Encoded: false,
};
};
Run Code Online (Sandbox Code Playgroud)
正如您从这一行中看到的,import { success } from './utils/log';我正在使用本机导入。
在我的 package.json 中,我指定了这个:
"type": "module"
Run Code Online (Sandbox Code Playgroud)
因为我需要告诉我的应用程序这是一个模块,我想本地导入。如果我不指定这一点,我会得到:
{
"errorType": "Runtime.UserCodeSyntaxError",
"errorMessage": "SyntaxError: Cannot use import statement …Run Code Online (Sandbox Code Playgroud) javascript containers amazon-web-services node.js aws-lambda
aws-lambda ×10
node.js ×5
amazon-s3 ×3
containers ×1
encryption ×1
javascript ×1
python ×1
triggers ×1