11/10/2021, 3:22 AM
Hi, is there a best practice for running
npm build
inside pulumi? Here's the use case: We need to build and deploy a frontend REACT application to S3. And we need to know which stack to deploy while building the application, so we can set up the environment variables properly. For example, if we are deploying to
, we should run
ENV=dev npm build
. Since we can easily get the stack name in pulumi, it would be convenient if I can run
npm build
inside pulumi.


11/10/2021, 3:58 AM
I'm not aware of a best practice. If I was doing this, I'd probably consider wrapping the build and pulumi app in a sinlgle script, rather than putting the build into the deploy. I'd be worried about sharing node_modules accidentally, using wrong versions of dependencies, etc.
I'm sure it can be done though.


11/10/2021, 9:29 AM
I am using pulumi only to deploy infrastructure (s3 in this case) and I use circleci for building the client and pushing it to the s3 bucket
you can use aws circleci orb for that, it's pretty easy
Copy code
- run:
    name: Deploy to S3
    command: |
      aws s3 sync dist/client s3://${S3_SITE_BUCKET_NAME} --no-progress --delete


11/10/2021, 10:10 AM
Not sure if running it as part of the pulumi deploy would be a good idea, but you should be able to do it using Dynamic Resource Providers. There is an example that may be useful to adapt - Likely to much more work that just doing it as a build step or wrapper script though...


11/10/2021, 12:50 PM
@wide-jackal-86020 the default way, when using Pulumi, is that Pulumi invokes
to create the needed resources. If you want to drive Pulumi from within your NodeJS code, have a look a the Automation API. In that setup, the Pulumi engine will be started by your NodeJS code and you can programmatically set the environment, stack config, etc.


11/10/2021, 1:53 PM
Thank you all!
wrapping the build and pulumi app in a sinlgle script,
This is what we are doing now. The problem is that the API endpoints are generated in other pulumi projects, they are not accessible when building the REACT application. @little-cartoon-10569 @miniature-king-36473
use circleci for building the client and pushing it to the s3 bucket
CI/CD works, But we don't have CI/CD setup for every stack. @sparse-spring-91820
Pulumi invokes 
 to create the needed resources.
This is what I am thinking to give it a try. Thank you for sharing the other way of driving Pulumi from within NodeJS code using the Automation API. 👍 @limited-rainbow-51650