Sheifa
Sheifa

Reputation: 33

How do I store encrypted env variables in Altostra ENV?

I have an Altostra project with a Lambda function that listens on SNS topic, and needs to call another service using an API Token. I need to save the API Key as an env variable, how do I keep it encrypted? Could anybody help me with that? Thanks! enter image description here

enter image description here

Upvotes: 2

Views: 76

Answers (1)

Shiran David
Shiran David

Reputation: 46

It is not recommended to store sensitive data in an env variable, because it will be exposed to anyone who can access the Lambda. A better option is to store the API key in a SSM parameter. AWS SSM is a secured storage for sensitive data.

You can add a SSM parameter reference to an Altostra project and use it in the Lambda like so:

  1. Add a parameter to SSM in AWS web console (Type = SecureString).
  2. Add a SSM resource and the parameter name of the API key: enter image description here
  3. Connect the Lambda to the SSM resource: enter image description here
  4. In the Lambda code, import SSM from aws-sdk, and call ssm.getParameter() in order to use the api-key:

import { SSM } from 'aws-sdk';
const ssm = new SSM();

const param = await ssm.getParameter({
          Name: 'api-key',
          WithDecryption: true,
        }).promise();

Upvotes: 3

Related Questions