Jan 01, 1970
const AWS = require('aws-sdk'); const lambda = new AWS.Lambda(options); const result = await lambda.invoke(invokeParams).promise(); const resultPayload = JSON.parse(result.Payload)
const { LambdaClient, InvokeCommand } = require('@aws-sdk/client-lambda'); const { toUtf8 } = require('@aws-sdk/util-utf8-node'); const command = new InvokeCommand(invokeParams); const result = await lambda.send(command); const resultPayload = JSON.parse(toUtf8(result.Payload));// Now the result payload is a Uint8 array that needs to be decoded
Tại thời điểm viết bài, gói @aws-sdk/util-utf8-node được đánh dấu là để ủng hộ @aws-sdk/util-utf8 . Nhưng trong thời gian chạy lambda, nodejs18.x chưa được bao gồm, vì vậy nếu bạn muốn sử dụng nó, bạn phải thêm nó vào phần phụ thuộc sản xuất dự án của mình.
const AWS = require('aws-sdk'); dynamoDbClient = new AWS.DynamoDB.DocumentClient(options); await dynamoDbClient.put(params).promise(); await dynamoDbClient.get(params).promise(); await dynamoDbClient.update(params).promise(); await dynamoDbClient.update(params).promise(); await dynamoDb.delete(params).promise(); await dynamoDb.scan(params).promise(); await dynamoDb.query(params).promise();
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb'); const { DynamoDBDocument, GetCommand, PutCommand, DeleteCommand, QueryCommand, UpdateCommand, ScanCommand, } = require('@aws-sdk/lib-dynamodb'); const dynamoDbClient = new DynamoDBClient(options); const docClient = DynamoDBDocument.from(dynamoDbClient); await docClient.send(new PutCommand(params)); await docClient.send(new GetCommand(params)); await docClient.send(new UpdateCommand(params)); await docClient.send(new UpdateCommand(params)); await docClient.send(new DeleteCommand(params)); await docClient.send(new ScanCommand(params)); await docClient.send(new QueryCommand(params));
Nếu bạn đã từng xử lý một số luồng từ bảng DynamoDB và sử dụng chức năng không theo thứ tự , v2:
const AWS = require('aws-sdk'); const {unmarshall} = AWS.DynamoDB.Converter;
const { unmarshall } = require('@aws-sdk/util-dynamodb');
const AWS = require('aws-sdk'); const s3Client = new AWS.S3(options); s3Client.upload(params, callBack);
const { S3Client } = require('@aws-sdk/client-s3'); const { Upload } = require('@aws-sdk/lib-storage'); const s3Client = new S3Client(options); const parallelUploads3 = new Upload({ client: s3Client, params }); const result = await parallelUploads3.done();
const AWS = require('aws-sdk'); const snsClient = new AWS.SNS(options); await snsClient.publish(data).promise();
const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns'); const snsClient = new SNSClient(options); await snsClient.send(new PublishCommand(data));