-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathawsIntegration.ts
More file actions
39 lines (32 loc) · 1.15 KB
/
awsIntegration.ts
File metadata and controls
39 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { SSM } from "@aws-sdk/client-ssm";
import { fromIni, fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { AWS_REGION } from "./awsRegion";
import { APP } from "./constants";
const LOCAL_PROFILE = "workflow";
export const IS_RUNNING_LOCALLY = !process.env.LAMBDA_TASK_ROOT;
export const STAGE = process.env.STAGE || "CODE"; // locally we use CODE AppSync API
export const standardAwsConfig = {
region: AWS_REGION,
credentials: IS_RUNNING_LOCALLY
? fromIni({ profile: LOCAL_PROFILE })
: fromNodeProviderChain(),
};
const ssm = new SSM(standardAwsConfig);
const paramStorePromiseGetter =
(WithDecryption: boolean) => (nameSuffix: string) => {
const Name = `/${APP}/${nameSuffix}`;
return ssm
.getParameter({
Name,
WithDecryption,
})
.then((result) => {
const value = result.Parameter?.Value;
if (!value) {
throw Error(`Could not retrieve parameter value for '${Name}'`);
}
return value;
});
};
export const pinboardSecretPromiseGetter = paramStorePromiseGetter(true);
export const pinboardConfigPromiseGetter = paramStorePromiseGetter(false);