Paul Swail
05/20/2022, 2:06 PM/{appName}/{stage}
prefixSeth Geoghegan
05/20/2022, 2:13 PMimport { 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!,
});
}
Seth Geoghegan
05/20/2022, 2:14 PMthdxr
05/20/2022, 2:14 PMthdxr
05/20/2022, 2:14 PMthdxr
05/20/2022, 2:15 PMPaul Swail
05/20/2022, 2:17 PMSeth Geoghegan
05/20/2022, 2:18 PM/<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.
"scripts": {
"ssm:list": "aws ssm get-parameters-by-path --recursive --with-decryption --path=/${npm_package_name} --region=${npm_package_region} --profile=${npm_package_myStage}"
}
Paul Swail
05/20/2022, 2:18 PMSeth Geoghegan
05/20/2022, 2:18 PMPaul Swail
05/20/2022, 2:18 PMthdxr
05/20/2022, 2:19 PM/myapp/fallback/STRIPE_KEY
and that way each developer won't have to set it under /myapp/dax/STRIPE_KEY
thdxr
05/20/2022, 2:19 PMPaul Swail
05/20/2022, 2:20 PMPaul Swail
05/20/2022, 2:22 PM$npm_package_
variables in your script look sweet. I never knew you could do that.Paul Swail
05/20/2022, 2:23 PMnpm_package_myStage
in your package.json file?thdxr
05/20/2022, 2:23 PMSeth Geoghegan
05/20/2022, 2:27 PM{
"packageName": "my-service-name",
"myStage": "SSO-PROFILE-NAME-HERE",
"region":"us-east-1",
"scripts": {
...
}
}
Seth Geoghegan
05/20/2022, 2:28 PMscript
Paul Swail
05/20/2022, 2:31 PMthdxr
05/20/2022, 2:38 PMAWS_PROFILE=<company>-dev
Seth Geoghegan
05/20/2022, 2:39 PMdev
), so I use $(whoami)
as a sensible default. I generally set the profile to a parameter named profile
. A less misleading example:
{
"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}"
}
}
Paul Swail
05/20/2022, 2:41 PMRudi
05/20/2022, 6:58 PMRudi
05/20/2022, 6:59 PMRudi
05/20/2022, 7:00 PMSeth Geoghegan
05/20/2022, 7:22 PMRudi
05/21/2022, 4:22 PMRudi
05/21/2022, 4:22 PMRudi
05/21/2022, 4:25 PM{
"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"
}
Rudi
05/21/2022, 4:39 PMRudi
05/21/2022, 4:42 PMRudi
05/21/2022, 4:42 PM