---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/segment/connections/functions/aws-sdk-upgrade#article
headline: Segment Functions AWS SDK v3 Upgrade
description: Migrate your Segment source, destination, and insert functions from AWS SDK for JavaScript v2 to v3 using the AWSv3 global in the Functions runtime.
url: https://www.twilio.com/docs/segment/connections/functions/aws-sdk-upgrade
inLanguage: en
dateModified: 2026-10-08T15:19:58.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# Segment Functions AWS SDK v3 Upgrade

> \[!NOTE]
>
> *Amazon Web Services* (AWS) ended support for the **AWS SDK for JavaScript v2** on *September 8, 2025*. Segment added [AWS SDK v3][] to the Functions runtime, available as `AWSv3`.

Twilio Segment keeps the libraries available to Functions current with industry standards. AWS moved the AWS SDK for JavaScript v2 into maintenance mode in September 2024 and ended support on September 8, 2025. AWS stopped providing new features, bug fixes, or security patches to SDK v2. You can use AWS SDK v3 in the Functions runtime alongside v2.

## What do I need to do?

If your function uses AWS:

1. Update your code to use `AWSv3` instead of `AWS`.
2. Test and redeploy your function.

Unlike the Node.js runtime upgrade, *this upgrade requires code changes*. Redeploying your function alone doesn't migrate it to AWS SDK v3.

## What happens if I take no action?

Your deployed functions continue to run on AWS SDK v2.

* If you create a function that uses AWS, use `AWSv3`.
* Until Twilio removes AWS SDK v2 from the Functions runtime, existing functions that use `AWS` continue to work.
* After Twilio removes `AWS`, functions that use it fail. Twilio will provide advance notice.

> \[!NOTE]
>
> Regardless of any other planned changes to your function, Twilio Segment recommends migrating to AWS SDK v3 as soon as possible.

## How do I upgrade to AWS SDK v3?

> \[!WARNING]
>
> AWS SDK v3 changes how Twilio Segment returns some responses and errors. Before you deploy your updated function, test it with sample events and confirm it behaves as expected.

### Update your function code

Access AWS services through `AWSv3.<Service>`.

> \[!NOTE]
>
> ## v2
>
> ```js
> const s3 = new AWS.S3()
> const data = await s3.getObject({ Bucket, Key }).promise()
> ```
>
> ## v3
>
> ```js
> const { S3Client, GetObjectCommand } = AWSv3.S3
> const s3 = new S3Client({ region: 'us-west-2' })
> const data = await s3.send(new GetObjectCommand({ Bucket, Key }))
> ```

> \[!NOTE]
>
> ## v2
>
> ```js
> const { Credentials } = await new AWS.STS().assumeRole(params).promise()
> AWS.config.update({ credentials: new AWS.Credentials(
>   Credentials.AccessKeyId, Credentials.SecretAccessKey, Credentials.SessionToken) })
> const s3 = new AWS.S3()
> ```
>
> ## v3
>
> ```js
> const { STSClient, AssumeRoleCommand } = AWSv3.STS
> const { Credentials } = await new STSClient({ region: 'us-west-2' })
>   .send(new AssumeRoleCommand(params))
>
> const s3 = new AWSv3.S3.S3Client({
>   region: 'us-west-2',
>   credentials: {
>     accessKeyId: Credentials.AccessKeyId,
>     secretAccessKey: Credentials.SecretAccessKey,
>     sessionToken: Credentials.SessionToken
>   }
> })
> ```

### Changes that apply to most functions

| What                   | v2                                       | v3                                                                             |
| ---------------------- | ---------------------------------------- | ------------------------------------------------------------------------------ |
| Create a client        | `new AWS.S3()`                           | `new AWSv3.S3.S3Client({ region })`                                            |
| Make a call            | `s3.getObject(params).promise()`         | `s3.send(new GetObjectCommand(params))`                                        |
| Callbacks              | `s3.getObject(params, (err, data) => …)` | Use `await` with `.send()`                                                     |
| Region                 | Inherited from `AWS.config`              | Required on every client: `{ region: '…' }`                                    |
| Credentials            | `AWS.config.update({ credentials })`     | Pass per client: `credentials: { accessKeyId, secretAccessKey, sessionToken }` |
| Config object          | `new AWS.Config({ … })`                  | No v3 equivalent — pass `{ region, credentials }` to each client               |
| Read an S3 object body | `data.Body.toString()`                   | `await data.Body.transformToString()`                                          |
| Read other binary data | `value.toString('utf8')`                 | `Buffer.from(value).toString('utf8')`                                          |
| Check an error type    | `err.code === 'NoSuchKey'`               | `err.name === 'NoSuchKey'`                                                     |
| Check an error status  | `err.statusCode`                         | `err.$metadata.httpStatusCode`                                                 |

### Changes that apply as needed

| What                      | v2                                             | v3                                                                             |
| ------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------ |
| Upload to S3              | `s3.upload(params).promise()`                  | `new AWSv3.S3Upload.Upload({ client, params }).done()`                         |
| DynamoDB DocumentClient   | `new AWS.DynamoDB.DocumentClient()`            | `AWSv3.DynamoDBDocument.DynamoDBDocumentClient.from(client)`                   |
| Wait for a resource       | `s3.waitFor('objectExists', params).promise()` | `await AWSv3.S3.waitUntilObjectExists({ client }, params)`                     |
| Paginate results          | `.eachPage(…)`                                 | `for await (const page of AWSv3.S3.paginateListObjectsV2({ client }, params))` |
| Retry and timeout options | `maxRetries`, `httpOptions`                    | `maxAttempts` (retries + 1), `requestHandler`                                  |
| S3 path style             | `s3ForcePathStyle: true`                       | `forcePathStyle: true`                                                         |
| Custom endpoint           | `new AWS.Endpoint(url)`                        | `endpoint: ''`                                                                 |
| EventBridge               | `new AWS.CloudWatchEvents()`                   | `AWSv3.EventBridge`                                                            |
| `apiVersion` option       | `apiVersion: '2012-08-10'`                     | Ignored in v3; you can remove it                                               |

> \[!NOTE]
>
> To import the AWS SDK, use the `AWSv3` global. You can't import it with `require()`.

### Test and deploy your function

In the Segment app, update your code in the **Functions** editor, then send a sample event.

1. Open your function.
2. Update your code for `AWSv3`.
3. To send a sample event, use the **Test** tab. Confirm the function behaves as expected.
4. Click **Save & Deploy**. This deploys the updated function.

With the Public API, update your function's code then deploy an updated version. To find the endpoints that apply to your function type, see the [Public API reference][].

Are you using an AWS feature not covered here? \[Contact Segment Support]\[].

[AWS SDK v3]: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest

[Contact Segment Support](https://segment.com/help/contact/)

[Public API reference]: https://docs.segmentapis.com/tag/Functions
