diff --git a/lib/pipeline.ts b/lib/pipeline.ts index 6bed985..7ae6288 100644 --- a/lib/pipeline.ts +++ b/lib/pipeline.ts @@ -38,7 +38,8 @@ export interface PipelineProps { buildcmd: string; outputdir: string; }; - buildEnvironmentVariables?: Record; + // buildEnvironmentVariables?: Record; + buildEnvironmentVariables: { key: string; resource: string; }[], // events eventTarget: string; @@ -281,14 +282,11 @@ export class PipelineConstruct extends Construct { } // environment variables - const buildEnvironmentVariables = Object.entries(props.buildEnvironmentVariables || {}).reduce( - (acc, [name, { value }]) => { - if (typeof value === 'string') { - acc[name] = { value, type: BuildEnvironmentVariableType.PARAMETER_STORE }; - } + const buildEnvironmentVariables: Record = (props.buildEnvironmentVariables || []).reduce( + (acc: Record, { key, resource }) => { + acc[key] = { value: resource, type: BuildEnvironmentVariableType.PARAMETER_STORE }; return acc; - }, - {} as Record + }, {} ); // create the cloudbuild project diff --git a/stack/SPAProps.ts b/stack/SPAProps.ts index 78b762b..84e39ab 100644 --- a/stack/SPAProps.ts +++ b/stack/SPAProps.ts @@ -62,10 +62,11 @@ export interface SPAProps extends StackProps { * If you have custom environments for build step, create Parameter Store variables as plaintext and use this format: * Must be in the same region as your stack. * - * MY_VARIABLE: { value: "/path-to/your-parameter" } - * + * buildEnvironmentVariables: [ + * { key: 'PUBLIC_EXAMPLE', resource: '/path-to/your-parameter' } + * ] */ - readonly buildEnvironmentVariables?: Record; + readonly buildEnvironmentVariables?: { key: string; resource: string; }[]; /** * Optional. If you have a custom CloudFront Functions file for your app, provide the relative path to the file. diff --git a/stack/SPAStack.ts b/stack/SPAStack.ts index 9bc9a8a..e4f206c 100644 --- a/stack/SPAStack.ts +++ b/stack/SPAStack.ts @@ -61,7 +61,7 @@ export class SPAStack extends Stack { buildcmd: props.buildProps?.buildcmd as string, outputdir: props.buildProps?.outputdir as string, }, - buildEnvironmentVariables: props.buildEnvironmentVariables as Record, + buildEnvironmentVariables: props.buildEnvironmentVariables as { key: string; resource: string }[], eventTarget: props.eventTarget as string }); diff --git a/templates/spa.ts b/templates/spa.ts index ef1a545..90ca72c 100644 --- a/templates/spa.ts +++ b/templates/spa.ts @@ -42,6 +42,11 @@ const appStackProps: SPAProps = { hostedZoneId: 'Z1D633PJRANDOM', globalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abcd1234-abcd-1234-abcd-1234abcd1234', + // Custom buildtime environment variables + // buildEnvironmentVariables: [ + // { key: 'PUBLIC_EXAMPLE', resource: '/path-to/your-parameter' } + // ] + // Custom Cloudfront Functions // edgeFunctionFilePath: 'custom.js',