Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to download .env file with build environment variables from S3 to a local dev environment #17

Merged
merged 3 commits into from
May 1, 2024

Conversation

tmokmss
Copy link
Owner

@tmokmss tmokmss commented May 1, 2024

Usage

  1. add outputEnvFile flag, and run cdk deploy.
    new NodejsBuild(this, 'ExampleBuild', {
      assets: [
        {
          path: 'example-app',
          exclude: ['dist', 'node_modules'],
        },
      ],
      destinationBucket: dstBucket,
      outputSourceDirectory: 'dist',
      buildCommands: ['npm ci', 'npm run build'],
      buildEnvironment: {
        VITE_API_ENDPOINT: api.url,
        VITE_BUKCET_NAME: dstBucket.bucketName,
      },
      outputEnvFile: true, // ADD THIS FLAG
    });
  1. you will get stack outputs like this:
 ✅  NodejsTestStack

✨  Deployment time: 278.49s

Outputs:
NodejsTestStack.ExampleBuildDownloadEnvFileC240151B = aws s3 cp s3://cdk-hnb659fds-assets-123456789012-ap-northeast-1/deploy-time-build/NodejsTestStack/ExampleBuild61F1D79B/6a4113a1b53dee719f931a51321ecec7.env .env.local
  1. run the command in your local machine, and you will get your .env file.
$ aws s3 cp s3://cdk-hnb659fds-assets-123456789012-ap-northeast-1/deploy-time-build/NodejsTestStack/ExampleBuild61F1D79B/6a4113a1b53dee719f931a51321ecec7.env .env.local
$ cat .env.local
VITE_API_ENDPOINT=https://asdfg.execute-api.ap-northeast-1.amazonaws.com/prod/
VITE_BUKCET_NAME=nodejsteststack-dstbucket3e241bf2-dwmxxxx

@tmokmss tmokmss merged commit 6065025 into main May 1, 2024
5 checks passed
@tmokmss tmokmss deleted the download-dotenv branch May 1, 2024 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant