---
title: "AWS web server with manual provisioning (in Python)"
description: "An example of manually configuring an AWS EC2 virtual machine"
url: "https://www.pulumi.com/dev/examples/aws-py-ec2-provisioners/"
image: "https://www.pulumi.com/assets/og/dev/examples/aws-py-ec2-provisioners.png"
---

# AWS web server with manual provisioning (in Python)

An example of manually configuring an AWS EC2 virtual machine

- Source on GitHub: https://github.com/pulumi/examples/tree/master/aws-py-ec2-provisioners
- Deploy with Pulumi: https://app.pulumi.com/new?template=https%3A%2F%2Fgithub.com%2Fpulumi%2Fexamples%2Ftree%2Fmaster%2Faws-py-ec2-provisioners

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/aws-py-ec2-provisioners) repo. Pull down just this directory to follow along:

```bash
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-py-ec2-provisioners
cd pulumi-examples/aws-py-ec2-provisioners
```

This demonstrates using the [`pulumi_command`](https://www.pulumi.com/registry/packages/command/) package to accomplish post-provisioning configuration steps.

Using these building blocks, one can accomplish much of the same as Terraform provisioners.

## Prerequisites

1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
2. [Configure AWS credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)
3. [Install Python](https://www.pulumi.com/docs/intro/languages/python/)

## Deploying the example

1. Create a new stack:

    ```bash
    pulumi stack init dev
    ```

1. Generate an OpenSSH keypair for use with your server, as per the AWS [requirements][1]:

    ```bash
    ssh-keygen -t rsa -f rsa -b 4096 -m PEM
    ```

    This will output two files, `rsa` and `rsa.pub`, in the current directory. Be sure not to commit these files!

1. Configure the stack so that the public key is used by your EC2 instance, and the private key is used for subsequent SCP and SSH steps that will configure your server after it is stood up:

    ```bash
    cat rsa.pub | pulumi config set publicKey --
    cat rsa | pulumi config set privateKey --secret --
    ```

    Notice that we've used `--secret` for `privateKey`. This ensures the private key is stored as an encrypted [Pulumi secret](https://www.pulumi.com/docs/intro/concepts/secrets/).

1. Set your desired AWS region:

    ```bash
    pulumi config set aws:region us-west-2
    ```

1. Install dependencies:

    ```bash
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    ```

1. Deploy the stack. All resources will be provisioned and configured:

    ```bash
    pulumi up
    ```

## Cleaning up

Once you're finished experimenting, destroy your stack and remove it to avoid incurring any additional cost:

```bash
pulumi destroy
pulumi stack rm
```

[1]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws
