> For the complete documentation index, see [llms.txt](https://spacelift-io.gitbook.io/spacelift/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://spacelift-io.gitbook.io/spacelift/vendors/pulumi/getting-started/python.md).

# Python

From this article you can learn how to setup a Pulumi JavaScript Stack in Spacelift

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-py-webserver](https://github.com/pulumi/examples/tree/master/aws-py-webserver).

In the root of the repository (not the aws-py-webserver directory), add a new file:

{% code title=".spacelift/config.yml" %}

```yaml
version: "1"

stack_defaults:
  before_apply:
    - pip install -r requirements.txt
```

{% endcode %}

`before_apply` is not yet exposed through the interface like `before_init`, so you have to set it through the config file.

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-py-webserver`, as we want to run Pulumi in this subdirectory only.
* Add one before init script: `pip install -r requirements.txt`, which will install all necessary dependencies, before initializing Pulumi itself. This will need to run both when [initializing](/spacelift/concepts/run.md#initializing) and before [applying](/spacelift/concepts/run.md#applying).
* Set the runner image to `public.ecr.aws/spacelift/runner-pulumi-python: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-python).

![Define behavior.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MO_znCKLt622BclmQA_%2F-MOaqR8Rxisr_ZKSE8Fz%2Fimage.png?alt=media\&token=01e5488f-4c91-4845-bc70-07e5c3f0bd92)

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-python-pulumi-spacelift-stack`.

![Configure backend.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOVyTxzMD3gLLyh3cnI%2F-MOWuZQRF0anMkOAx3LL%2Fimage.png?alt=media\&token=70f49cf6-4465-4367-9548-8e6d1bf75e51)

{% 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](/spacelift/integrations/cloud-providers/aws.md#setting-up-aws-integration).

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

![Configure enviornment.](https://3862190545-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LshwwDZmA4HXN0k9e8O%2F-MOVyTxzMD3gLLyh3cnI%2F-MOWsjVYF74vNo_SwxpW%2Fimage.png?alt=media\&token=7f0ecfe9-3675-41b7-abe4-4ad9f013ee6f)

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-MOGaX4BTu8chvQg2tbu%2F-MOGenL37B-xiFTg93xE%2Fimage.png?alt=media\&token=e74df357-fa9d-41dd-b7e2-9069d00efd3d)

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-MOGaX4BTu8chvQg2tbu%2F-MOGfLMTR8U07vxS_L6p%2Fimage.png?alt=media\&token=09514c9e-bfda-4bda-b07d-9e8b82794f96)

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

```
~> curl ec2-3-125-48-55.eu-central-1.compute.amazonaws.com
Hello, World!
```

In order to clean up, open the [Tasks](/spacelift/concepts/run/task.md) 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-MOGaX4BTu8chvQg2tbu%2F-MOGftk-gHqRXhf2tSw-%2Fimage.png?alt=media\&token=2206937e-519e-4e5c-9701-0ba7077ad88c)
