Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Web server using Amazon EC2

Basic C# example of an AWS web server accessible over HTTP.

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-cs-webserver
cd pulumi-examples/aws-cs-webserver

An example based on the Amazon sample at: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/deploying.applications.html. The example deploys an EC2 instance and opens port 80.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install .NET

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Set the AWS region to deploy into:

    Terminal window
    pulumi config set aws:region us-west-2
  3. Deploy the stack:

    Terminal window
    pulumi up
  4. View the host name and IP address of the instance via stack output:

    Terminal window
    pulumi stack output
    Current stack outputs (2):
    OUTPUT VALUE
    PublicDns ec2-34-217-176-141.us-west-2.compute.amazonaws.com
    PublicIp 34.217.176.141
  5. Verify that the EC2 instance exists, by either using the AWS Console or running aws ec2 describe-instances.

    From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your stack.

Cleaning up#

Once you’ve finished experimenting, tear down your stack’s resources by destroying and removing it:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.