skip to Main Content

I’m writing a app that runs on EC2, and currently moving from local to prod env.

I’ve read a few blogs that said I should store the env params in AWS SSM instead of export them in the terminal.

My question is that, should I fetch these env variables every time the app makes an API call (I think it’s not a good option). Or, should I fetch and then store it somewhere within the app? If so, where should I store these env variables after I’ve fetched them?

const getParametersResponse = await ssm.getParameters({
    Names: [
      "Client_key",
      "Client_Id"
    ],
    WithDecryption: true
  }).promise();

I should run this fetch function getParametersResponse every time the app makes an API call or I should just run it once and then store it somewhere? If so, where do I store these keys?

2

Answers


  1. Create a service in your application and fetch only once when you first boot the app, after that just read it from service without getting it from SSM.

    Login or Signup to reply.
  2. Why do you think an API call to get data is a problem?

    Every time you go to a site with oAuth, they check if you are logged in or not by doing an API call to the oAuth server. Just because you have a cookie/local storage data doesn’t mean in backend it is not checked.
    Every request you send to backend there are bunch of middlewares (oauth, logs, metric etc etc) where they do API calls before the call actually reaches the intended microservice.

    But in your case, if you dont want to read parameter all the time then after getting parameters store it somewhere. Like memcache, redis or maybe just in a variable in your code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search