Load Secrets from env.yml


#1

Link to chapter - https://serverless-stack.com/chapters/load-secrets-from-env-yml.html


#2

I am getting this error.

{
    "statusCode": 500,
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Credentials": true
    },
    "body": "{\"message\":\"You did not provide an API key, though you did set your Authorization header to \\\"null\\\". Using Bearer auth, your Authorization header should look something like 'Authorization: Bearer YOUR_SECRET_KEY'. See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.\"}"

If I hard code const stripe = stripePackage(“sk_test_******” ); into billing.js it works but if I follow instructions to access it through env.yml I get the above error.

Any idea what is going wrong?


#3

The problem is mostly solved. I found that if I put the environmental variables in the billing function in serverless.yml (as per https://serverless-stack.com/chapters/serverless-environment-variables.html), I can access them. But anywhere else the variable will be passed as undefined.


#4

Hmm can you make sure that the env.yml is correctly placed in the same folder as your serverless.yml?


#5

I have the same issue.


#6

Can you post some details on the issue you are having?


#7

It seems that it is not possible for us to access the secret keys from the env.yml when using them in the billing.js file.

Instead it returns ‘undefined’:

process.env.stripeSecretKey

As a work around we hard code them in the API request and it works.

/// Hardcoding the secret key
const secretAPIKey = “sk_test_I0kUXXXXXXXXXXXX”

export async function main(event, context) {
const { storage, source } = JSON.parse(event.body);
const amount = calculateCost(storage);
const description = “Scratch charge”;

// Using the hard coded key instead of loading it from the  environment variables
const stripe = stripePackage(secretAPIKey);

#8

Are you running this locally? Cos it works fine in the sample repo.