---
description: >-
  From this article you can learn how to setup a Pulumi JavaScript Stack in
  Spacelift
---

# JavaScript

In order to follow along with this article, you'll need an AWS account.

Start with forking the [Pulumi examples repo](https://github.com/pulumi/examples), we'll be setting up an example directory from there, namely [aws-js-webserver](https://github.com/pulumi/examples/tree/master/aws-js-webserver).

Now let's open Spacelift and create a new Stack, choose the examples repo you just forked. In the second step you'll have to change multiple default values:

* Set the project root to `aws-js-webserver`, as we want to run Pulumi in this subdirectory only.
* Add one before init script: `npm install`, which will install all necessary dependencies, before initializing Pulumi itself. The outputs will be persisted in the workspace and be there for the [Planning](../../../../concepts/run#planning) and [Applying](../../../../concepts/run#applying) phases.
* Set the runner image to `public.ecr.aws/spacelift/runner-pulumi-javascript:latest`&#x20;
  * Pinning to a specific Pulumi version is possible too, using a tag like `v2.15.4` - you can see the available versions [here](https://gallery.ecr.aws/spacelift/runner-pulumi-javascript).

![Define behavior.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MO_znCKLt622BclmQA_%2F-MOaqDQLVmKVJU41l440%2Fimage.png?alt=media\&token=057c1708-dc8a-45ae-95a9-c4d6ae94034b)

In the third step, choose Pulumi as your Infrastructure as Code vendor. You'll have to choose:

* A state backend, aka login URL. This can be a cloud storage bucket, like `s3://pulumi-state-bucket`, but it can also be a Pulumi Service endpoint.&#x20;
* A stack name, which is how the state for this stack will be namespaced in the state backend. Best to write something close to your stack name, like `my-javascript-pulumi-spacelift-stack`.

![Configure backend.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOVyTxzMD3gLLyh3cnI%2F-MOWuibvfKK9hqhTmWMS%2Fimage.png?alt=media\&token=5a6bd1ee-f970-4a93-8342-a3edd5dd5f00)

{% hint style="info" %}
You can use https://api.pulumi.com as the Login URL to use the official Pulumi state backend. You'll also need to provide your Pulumi access token through the PULUMI\_ACCESS\_TOKEN environment variable.
{% endhint %}

You'll now have to set up the AWS integration for the Stack, as is described in [AWS](../../../../integrations/cloud-providers/aws#setting-up-aws-integration).

Go into the [Environment](../../../concepts/configuration/environment) tab in your screen, add an **AWS\_REGION** environment variable and set it to your region of choice, i.e. `eu-central-1`.

![Configure environment.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOVyTxzMD3gLLyh3cnI%2F-MOWsTHph0k5R09mVZLo%2Fimage.png?alt=media\&token=7bb40c67-310a-473d-a686-9ffbd9a2aabb)

You can now trigger the Run manually in the Stack view, after the planning phase is over, you can check the log to see the planned changes.

![Pending confirmation.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOGMZ6J6ZAjxuvgjhdz%2F-MOGQM7oY0wQI2B9cDqZ%2Fimage.png?alt=media\&token=87967974-00e0-401b-8f89-dedfb6246f86)

Confirm the run to let it apply the changes, after applying it should look like this:

![Applied](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOGMZ6J6ZAjxuvgjhdz%2F-MOGREjanQvK8RWEm1vX%2Fimage.png?alt=media\&token=461eb97e-dbc4-4fdc-beb0-d8e9ba8559c9)

We can see the publicHostName stack output. If we try to curl it, lo and behold:

```
~> curl ec2-18-184-240-9.eu-central-1.compute.amazonaws.com
Hello, World!
```

In order to clean up, open the [Tasks](../../../concepts/run/task) tab, and perform `pulumi destroy --non-interactive --yes` there.

![Performing cleanup task.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOGMZ6J6ZAjxuvgjhdz%2F-MOGS45Vk-OknbzYbr09%2Fimage.png?alt=media\&token=a372ecfd-993b-4111-9827-b8f3f8d738e7)

Which will destroy all created resources.

![Destruction complete.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOGMZ6J6ZAjxuvgjhdz%2F-MOGSw1nyZctT_W-eeMT%2Fimage.png?alt=media\&token=30c71adb-1b16-42dc-ae10-ff1e26dc647f)

