Is there a mechanism for deploying settings to SSM...
# sst
p
Is there a mechanism for deploying settings to SSM Parameter Store using SST? I’m thinking of settings such as secret third-party API keys here and not stack outputs. In the past, I’ve created a util to read from a local dotenv file (not version controlled) and write these to SSM under an
/{appName}/{stage}
prefix
s
I generally use the CDK directly for this:
Copy code
import { StackContext } from "@serverless-stack/resources";
import * as ssm from "aws-cdk-lib/aws-ssm";

// resources deployed only when running "locally"
export function MyStack({ stack, app }: StackContext) {

  // Create SSM parameter 
  new ssm.StringParameter(stack, "myParam", {
    description: "APIKey",
    parameterName: `/${stack.stage}/${app.name}/apiKey`,
    stringValue: process.env.MY_API_KEY!,
  });
}
Although, I'm sure the team is cooking up an SST native way of doing this
t
we're going to be baking this into our console
so you can set it in the UI, otherwise I usually just use the aws-cli to set them
also sst loads dot env files automatically so that approach could work too but you can't set encrypted SSM values this way
p
be nice to be able to do it in the console
s
Since I follow a standard naming convention across my SSM parameters (
/<app name>/<stage>/<param name>
), I've started added a little helper script in my
package.json
that lists all the SSM parameter values my stack defines.
Copy code
"scripts": {
    "ssm:list": "aws ssm get-parameters-by-path --recursive --with-decryption --path=/${npm_package_name} --region=${npm_package_region} --profile=${npm_package_myStage}"
}
p
just thinking of the workflow for a new developer joining a team with an app with multiple secrets in it. How do they quickly get those secret values into their own SSM params
s
mostly because I can never remember the AWS CLI options 🙂
p
nice!
t
if you have a single dev aws account for all developers, the new parameter thing has the concept of "fallback". So I'd specify
/myapp/fallback/STRIPE_KEY
and that way each developer won't have to set it under
/myapp/dax/STRIPE_KEY
if you have an aws account per developer then yeah you'd have to copy it around, don't have a go to way for that
p
yea I’m typically working in a shared dev account, so that fallback would work
@Seth Geoghegan those
$npm_package_
variables in your script look sweet. I never knew you could do that.
how are you setting
npm_package_myStage
in your package.json file?
t
me neither 😮
s
Yeah, I just found out about it myself! Unfortunately, it's just hard coded for now. Nothing too clever
Copy code
{
  "packageName": "my-service-name",
  "myStage": "SSO-PROFILE-NAME-HERE",
  "region":"us-east-1",
  "scripts": {
     ...
   }
}
Would be nice if those things were dynamic, but at least I don't have to set them manually on each
script
p
ah I just realised that it’s the AWS profile name and not the stage that you need in your CLI command. I think it makes sense for all devs to use the same SSO profile name when setting up AWS SSO CLI so this is fine to hardcode
t
yeah that's what I do as well
AWS_PROFILE=<company>-dev
s
Hm, I think I may have pasted a misleading script 🙂 I generally use $(whoami) as the stage name. I know SST will prompt for this if not present, but I am setting this up for a team of devs that might not be familiar with SST. I don't want them selecting a non-unique stage name (e.g.
dev
), so I use
$(whoami)
as a sensible default. I generally set the profile to a parameter named
profile
. A less misleading example:
Copy code
{
  "name": "my-service-name",
  "profile": "SSO-PROFILE-NAME-HERE",
  "region": "us-east-1",
  "scripts": {
    "start": "sst start --stage $(whoami) --profile=${npm_package_profile}",
    "ssm:list": "aws ssm get-parameters-by-path --recursive --with-decryption --path=/${npm_package_name} --region=${npm_package_region} --profile=${npm_package_profile}"
  }
}
p
that totally makes sense 👍🏻
r
Interesting, I've used bash scripts to create/update/delete aws Parameter store - I'm going to tinker using NPM and the inline variables with package.json.
My shell scripts would read from the environment, but also include checks to make sure those env vars do exist first.
@Seth Geoghegan Your demo code is way cool using SST, but there's no error check to make sure the env var is defined.
s
Good point, I should stop being so lazy and raise an error if undefined :)
r
Hmm .. custom package.json properties for me are always undefined when I try to reference them like so ${npm_package_region}
Only "valid" properties like name or version (etc) will print out
For example, a quick demo from scratch:
Copy code
{
  "name": "tester",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "region": "us-east-1",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "list": "echo --name=${npm_package_name} --region=${npm_package_region}"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
Works in older versions:
Oh well, will keep using shell scripts for secrets management.