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

SDK for JS v3 asks for AWS_* env variables but amplify does not accept "AWS" word #3629

Closed
4 tasks done
andre-mr opened this issue Jul 30, 2023 · 5 comments
Closed
4 tasks done
Assignees
Labels

Comments

@andre-mr
Copy link

Before opening, please confirm:

App Id

d3vc3r2jaskk9c

AWS Region

sa-east-1

Amplify Hosting feature

Backend builds, Environment variables, Frontend builds, SSR

Question

Hi.

I migrated a project to AWS-SDK For Javascript v3, and now I have some issues with credentials.
This doc says credentials from environment variables (method i was using in v2) are auto detected but with specific name convention: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN:
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-environment.html

Not using token part for now.

With version 2, I had to rename my variables starting with "AWS_", replacing with "AMAZON_" because amplify doesn't accept variables starting with "AWS" word.

Now I honestly don't know how this is intended for v3. SDK expecting "AWS_ACCESS_KEY_ID" but amplify doesn't accept this naming convention.

I tried to deploy to Vercel, wich doesn't have "AWS" prefix restriction, and it worked as a charm.

This is the file where I setup DocumentClient, where I defined credentials with v2 and now it doesn't need for Vercel (as v3 docs stated by the way):

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";

const Table = process.env.AMAZON_DYNAMODB_TABLE;
const AMAZON_REGION = process.env.AMAZON_REGION;
const client = new DynamoDBClient({ region: AMAZON_REGION });
const docClient = DynamoDBDocumentClient.from(client);

const AWSDynamoDB = () => {
  return docClient;
};

export { AWSDynamoDB, Table };

Any ideas to deal with that, other than downgrading to v2?

@andre-mr andre-mr added the question Further information is requested label Jul 30, 2023
@andre-mr
Copy link
Author

andre-mr commented Jul 31, 2023

Nevermind... found a solution, using "AMAZON_" instead of "AWS_" as I did with v2.

Just setup credentials parameter, this way:

const client = new DynamoDBClient({
  region: AMAZON_REGION,
  credentials: {
    accessKeyId: AMAZON_ACCESS_KEY_ID,
    secretAccessKey: AMAZON_SECRET_ACCESS_KEY,
  },
});

Really don't know why Amplify has "AWS*" as reserved prefix, since there are just a few default variables using that. 🤷‍♂️
You could revise this rule, to better match v3 convention about default env approach.

@Jay2113 Jay2113 added environment-variables usability and removed question Further information is requested labels Aug 1, 2023
@Jay2113 Jay2113 self-assigned this Aug 1, 2023
@Jay2113 Jay2113 removed the usability label Aug 16, 2023
@Jay2113
Copy link
Contributor

Jay2113 commented Aug 16, 2023

Hi @andre-mr 👋 , thanks for raising this with us!

You've correctly mentioned that Amplify Hosting does not allow the use of environment variables with a prefix of AWS* as it is reserved for internal use only and the following error will be returned in the console:

Operation failed - Environment variables cannot start with the reserved prefix "AWS".

We will update our documentation to accurately reflect the same.

@Jay2113
Copy link
Contributor

Jay2113 commented Mar 1, 2024

@andre-mr 👋 , our documentation has been updated to reflect this information: https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html.

@Jay2113 Jay2113 closed this as completed Mar 1, 2024
Copy link

github-actions bot commented Mar 1, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked.

@github-actions github-actions bot added the archived This issue has been locked. label Mar 1, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants