Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Encode and Decode for Lamda calls #480

Open
1 task
pjosols opened this issue Mar 22, 2023 · 2 comments
Open
1 task

[Feature]: Encode and Decode for Lamda calls #480

pjosols opened this issue Mar 22, 2023 · 2 comments
Labels
enhancement New feature or request p2 This is a standard priority issue

Comments

@pjosols
Copy link

pjosols commented Mar 22, 2023

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

@pjosols pjosols added the enhancement New feature or request label Mar 22, 2023
@trivikr
Copy link
Member

trivikr commented Mar 22, 2023

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?

@trivikr trivikr added the p2 This is a standard priority issue label Mar 22, 2023
@trivikr
Copy link
Member

trivikr commented Aug 1, 2023

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 #497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants