aws-sdk-js-codemod
aws-sdk-js-codemod copied to clipboard
[Feature]: Encode and Decode for Lamda calls
Self-service
- [ ] I'd be willing to implement this feature
Template name
v2-to-v3
Input code
const AWS = require("aws-sdk");
const lambda = new AWS.Lambda({ region: util_1.requireEnvironmentVariable('AWS_REGION') });
const sns = new AWS.SNS({ region: util_1.requireEnvironmentVariable('AWS_REGION') });
function getSnsPublishFunction(sns) {
return (input) => sns.publish(input).promise();
}
const params = {
FunctionName: lambdaName,
InvocationType: 'RequestResponse',
Payload: JSON.stringify(dbEvent),
};
const response = await lambda.invoke(params).promise();
const payload = JSON.parse(_.get(response, ['Payload']));
Expected Output
const {
Lambda
} = require("@aws-sdk/client-lambda"),
{
SNS, PublishCommand
} = require("@aws-sdk/client-sns");
const lambda = new Lambda({ region: util_1.requireEnvironmentVariable('AWS_REGION') });
const sns = new SNS({ region: util_1.requireEnvironmentVariable('AWS_REGION') });
function getSnsPublishFunction(sns) {
return (input) => {
const command = new PublishCommand(input);
sns.send(command);
}
}
const params = {
FunctionName: lambdaName,
InvocationType: 'RequestResponse',
Payload: new TextEncoder().encode(JSON.stringify(dbEvent)),
};
const response = await lambda.invoke(params);
const payload = JSON.parse(new TextDecoder('utf-8').decode(_.get(response, ['Payload'])));
Additional context
No response
We don't plan to convert client.operation() to client.send(new OperationCommand()) in v2-to-v3 transformer.
We may add a future transformer, say api-to-command, if there's a requirement which multiple users ask for.
About Encoder/Decoder, some mixin type support could be provided in JS SDK v3 which transformer can support, instead of using TextEncoder/TextDecoder. Can you create a feature request on v3 repo, or upvote an existing one, if present?
We may add a future transformer, say
api-to-command, if there's a requirement which multiple users ask for.
This will be tracked in https://github.com/awslabs/aws-sdk-js-codemod/issues/497