Hey, I know this is a really simple question… I’m ...
# general
b
Hey, I know this is a really simple question… I’m just looking for a guide or something for setting up environment variables so that I can deploy to AWS using
pulumi up
from my laptop, and have the service running with the proper configurations. (?)
b
how do you currently auth to AWS?
b
I’m looking for something analogous (or maybe better, storing the env vars in AWS, maybe via some CLI or something when deploying?) to setting the
environment
property in
serverless.yml
from Serverless Framework. That’s what I’m doing right now… it doesn’t seem like what you linked has a place for general environment variables that my service (and dependent utility library) would require… but maybe I’m misreading/misunderstanding.
b
I think you’re talking about configuration? https://www.pulumi.com/docs/intro/concepts/config/
b
Ah yes, exactly, configuration in Pulumi, AKA environment variables, which can be accessed in JavaScript using
process.env
or Python as
os.environ
etc… I guess I overlooked this due to all the CLI commands, but on closer read, I see that they’re defined in the Pulumi.*.yaml files. Thanks / sorry for missing that documentation page earlier.
b
if you want to grab environment variables you can just use the standard language mechanisms.
os.environ
will retrive them as normal because at the end of the day it’s just python
b
Thanks so far… I was able to create the configuration values inside config of my yaml like:
Copy code
name: service-name
description: blah...
runtime: nodejs
config:
  aws:region: us-east-1
  env:
    varName: 'whatever'
and I can access it fine using
Copy code
import { env } from 'node:process';

const config = new pulumi.Config();
const envVars = config.requireObject('env');

Object.entries(envVars as any).forEach(([name, value]) => {
  env[name] = String(value);
});
but… like, I’m not sure how to actually see the values when I type `console.debug(process.env)`… How do I get my consuming code, the code that is included as a dependency library within my function deployed in AWS Lambda, that expects certain environment variables to be set, to read these configurations?… At this point, they don’t truly seem to be environment variables in the usual sense, such that they can be accessed via, eg,
process.env.varName
.
b
if you’re reading values from configuration, they’re not environment variables. if you want to read an env var specifically, just use
process.env.varName
in your code I suggested configuration as a method to pass values to your program that you might need
b
Ah… so how do I create actual environment variables?
b
outside pulumi?
export MY_VAR="foo"
or inside pulumi? whatever you’d use for your language
b
Ah… I finally read the default GreetBot message and realized there was a #typescript channel that was more development-focused, somehow…. There was an example there with environment variables… I guess I must’ve missed that earlier, idk. Was very simple to implement, building off of what you pointed me to, on configurations, yesterday:
Copy code
import * as pulumi from '@pulumi/pulumi';
import { fxRateUpdater } from './useCases/cmsUpdater/fxRateUpdater';

const serviceName = 'cms-updater';
const config = new pulumi.Config();
const envVars = config.requireObject('env');

const lambda = new aws.lambda.CallbackFunction(`${serviceName}-lambda`, {
  policies: [aws.iam.ManagedPolicies.CloudWatchLogsFullAccess],
  environment: {
    variables: {
      ...envVars as any,
    },
  },
  callback: fxRateUpdater,
});
… worked like a charm! Neat way to separate the environment vars from the actual index.ts code, by separating out into a separate Pulumi.*.yaml file, as you’d directed me toward yesterday!