Skip to content

Commit

Permalink
docs(upgrading): add notes on Lambda invoke (#5094)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Aug 17, 2023
1 parent e5e93e6 commit 78200fc
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,52 @@ In v3, the similar utility class is available in [`@aws-sdk/rds-signer` package]
In v2, you can generate a signed URL to the speech synthesized by AWS Polly service with [`AWS.Polly.Presigner` class](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Polly/Presigner.html).

In v3, the similar utility function is available in [`@aws-sdk/polly-request-presigner` package](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_polly_request_presigner.html)

## Notes on Specific Service Clients

### Lambda

Lambda invocations response type differs in v3:

```js
import { Lambda } from "@aws-sdk/client-lambda";
import AWS from "aws-sdk";

const region = "...";

{
// v2
const lambda = new AWS.Lambda({ region });
const invoke = await lambda
.invoke({
FunctionName: "echo",
Payload: JSON.stringify({ message: "hello" }),
})
.promise();
// in v2, Lambda::invoke::Payload is automatically converted to string via a
// specific code customization.
const payloadIsString = typeof invoke.Payload === "string";
console.log("Invoke response payload type is string:", payloadIsString);

const payloadObject = JSON.parse(invoke.Payload);
console.log("Invoke response object", payloadObject);
}

{
const lambda = new Lambda({ region });
const invoke = await lambda.invoke({
FunctionName: "echo",
Payload: JSON.stringify({ message: "hello" }),
});
// in v3, Lambda::invoke::Payload is not automatically converted to a string.
// This is to reduce the number of customizations that create inconsistent behaviors.
const payloadIsByteArray = invoke.Payload instanceof Uint8Array;
console.log("Invoke response payload type is Uint8Array:", payloadIsByteArray);

// To maintain the old functionality, only one additional method call is needed:
// v3 adds a method to the Uint8Array called transformToString.
const payloadObject = JSON.parse(invoke.Payload.transformToString());
console.log("Invoke response object", payloadObject);
}
```

0 comments on commit 78200fc

Please sign in to comment.