Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to emulate AWS Parameter Store on local computer for lambda function development?

I'm using Serverless framework and NodeJS to develop my AWS Lambda function. So far, I have used .env file to store my secrets. So, I can get access to them in serverless.yml like this

provider:
  ...
  environment:
    DB_HOST: ${env:DB_HOST}
    DB_PORT: ${env:DB_PORT}

But now I need to use AWS Parameter Store instead of .env file. I have tried to find information about how to emulate it on my local machine, but I couldn't.

I think, I have to use one serverless config file on local and staging. I need a way to select somehow env values either from .env file (if it's local machine) or from Parameter Store (if it's AWS Lambda). Is there any way how to do it? Thanks!

like image 605
Ivan Banha Avatar asked Aug 28 '26 08:08

Ivan Banha


1 Answers

It should work like this: within your serverless.yml you can reference .env parameters with ${env:keyname} and AWS Parameters using the ${param:keyname} syntax.

If you need to support both of them you just need to write ${env:keyname, param:keyname}.

Here's an example:

provider:
  ...
  environment:
    ALLOWED_ORIGINS: ${env:ALLOWED_ORIGINS, param:ALLOWED_ORIGINS}
    AUTHORIZER_ARN: ${env:AUTHORIZER_ARN, param:AUTHORIZER_ARN}
    MONGODB_URL: ${env:MONGODB_URL, param:MONGODB_URL}
like image 108
marco.santonocito Avatar answered Aug 30 '26 23:08

marco.santonocito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!