0
votes

I'm using the AWS SDK in order to store images for my app. I'm using Firebase cloud functions rather than setting up my own server.

The AWS SDK is clever in that it can automatically detect environmental variables for connecting to an S3 instance: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-environment.html

The SDK automatically detects AWS credentials set as variables in your environment and uses them for SDK requests, eliminating the need to manage credentials in your application. The environment variables that you set to provide your credentials are:

AWS_ACCESS_KEY_ID

AWS_SECRET_ACCESS_KEY

AWS_SESSION_TOKEN (optional)

However, in Firebase, all environmental variables must be lowercase. https://firebase.google.com/docs/functions/config-env

Keep in mind that only lowercase characters are accepted in keys; uppercase characters are not allowed.

Is there any solution to setting AWS environmental variables in Firebase functions?

2

2 Answers

1
votes

You can use the Firebase environment variables in a client's config object:

in the cli:

firebase functions:config:set aws.access_key_id="your_key"
firebase functions:config:set aws.secret_access_key="your_key"

on cloud functions:

const someClient = new Client({
    region: "your_region",
    credentials: {
      accessKeyId: functions.config().aws.access_key_id,
      secretAccessKey: functions.config().aws.secret_access_key
    }
  });
0
votes

The Firebase config you're talking about are not in any way related to process environment variables that are used by the AWS SDK. While they have similar names, they are actually completely unrelated by implementation. You simply won't be able to use the Firebase tooling to create process environment variables used by AWS.

If you want to set up process env vars in Cloud Functions, you won't even be able to establish those with the Firebase tooling. You will have to make changes to environment variables in the Google Cloud console for the functions you have already deployed.