Load Secrets from env.yml


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


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?


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.


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


I have the same issue.


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


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’:


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);


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


am following the tutorial exactly as written, and I also get this 500 error


For 500 errors you should be able to log them. Whats the error you are seeing?