The Vercel platform has a list of reserved environment variable names that cannot be used for your deployments. If you try to use the AWS SDK without updating the configuration, the app will fail. In this article we will walk you through the best way to use your AWS environment variables with Vercel.

Adding Project Environment Variables

Before proceeding, you need to add your AWS environment variables securely. Please take a look at our documentation on environment variables to learn how to do so. It is important that you choose names that are not present on the reserved list. Instead of AWS_REGION you can use AWS_REGION_MYAPP, for example.

Using the aws.config.update Function

The AWS SDK documentation describes the config object. One of the functions included in the object is the update(), which allows you to set a new configuration for your code.

const aws = require('aws-sdk')

  'accessKeyId': process.env.AWS_ACCESS_KEY_ID_MYAPP,
  'secretAccessKey': process.env.AWS_SECRET_ACCESS_KEY_MYAPP,
  'region': process.env.AWS_REGION_MYAPP,
    'bucketname': process.env.AWS_BUCKET_NAME
  // (...)

// New S3 class
const s3 = new aws.S3()

module.exports = (req, res) => {
  // (...)

Updating the AWS SDK to use a custom defined set of credentials.

The code snippet above allows you to avoid any errors caused by using reserved environment variable names with a Vercel deployed app. You can adapt it to create other AWS resources as required.

Last Edited on September 1st 2020