aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
450 stars 113 forks source link

Using KMS or Parameter Store values in a FRONTEND amplify app? #2874

Open acomito opened 2 years ago

acomito commented 2 years ago

We are hosting a react app on amplify with no backend.

I see in the docs that you can use Parameter Store but it seems like that's only for backend applications?

https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html#access-env-vars

Is there anyway to get these into a frontend application? Maybe during a build? These env vars are purely for the frontend and no a security concern.

This is tangentially related to using doppler for env variables. Basically, the vars are synced between doppler and parameter store, but now I'm unclear how to get them into the runtime or build for the frontend amplify application.

Also open to ideas how to get them straight from doppler into amplify, if there's a way to bypass parameters/KMS.

tydonk commented 1 year ago

I have the same use case as @acomito, any updates on this question?

mkraenz commented 1 year ago

Hi, I just answered with a solution to this issue in https://github.com/aws-amplify/amplify-hosting/issues/3348#issuecomment-1476044689. The solution works on the frontend build (in my case NextJS+SSR + api routes), and from doppler. In doppler, I've set up the AWS SSM parameter store integration with base path /amplify/<my-app-id>/main/ for my amplify branch main for doppler environment dev (using dev because of testing purposes). Rebuilding resulted in the following frontend build logs (similar to what is shown in the linked comment)

 # Executing command: echo $secrets
 {"DOPPLER_CONFIG":"dev","DOPPLER_ENVIRONMENT":"dev","DOPPLER_PROJECT":"meetmecal-manualsetup","HELLOFROMDOPPLER":"hello there, i'm doppler","test2":"helloworld2"}