Skip to content

Commit

Permalink
Tidy up the examples
Browse files Browse the repository at this point in the history
This changes a number of things about our examples:

* Adopt a prefix strategy so that the examples sort nicely by
  cloud and language: <cloud>-<language>-<title>.

* Add the Python webserver example.

* Add the Kubernetes guestbook and Nginx webserver examples.

* Improve the README descriptions of the projects to be more
  specific, welcoming, and comprehensive.  For example, highlight
  the AWS, Azure, and Kubernetes flavors of the web server example.
  • Loading branch information
joeduffy committed Mar 31, 2018
1 parent 8cdf54c commit 2398e57
Show file tree
Hide file tree
Showing 94 changed files with 554 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.pulumi
Pulumi.*.yaml
.pulumi/
node_modules/
Pulumi.*.yaml
*.pyc
49 changes: 40 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@
# Pulumi Examples

This repository contains examples of using Pulumi to build and deploy cloud applications and infrastructure.
This repository contains examples of using Pulumi to build and deploy cloud applications and infrastructure.

Each example has a two-part prefix, `<cloud>-<language>`, to indicate which `<cloud>` and `<language>` it pertains to.
The cloud is one of `aws` (for [Amazon Web Services](https://github.com/pulumi/pulumi-aws)), `azure` (for [Microsoft
Azure](https://github.com/pulumi/pulumi-azure)), `gcp` (for [Google Cloud
Platform](https://github.com/pulumi/pulumi-gcp)), `kubernetes` (for
[Kubernetes](https://github.com/pulumi/pulumi-kubernetes))), or `cloud` (for
[Pulumi's cross-cloud programming framework](https://github.com/pulumi/pulumi-cloud)).

See the [Pulumi documentation](https://docs.pulumi.com) for more details on getting started with Pulumi.

### [URL shortener](url-shortener/)
### Web Server

This is one of our most basic examples, showing how to provision a simple Linux webserver serving traffic on port 80.
This example is available in multiple flavors:

* [AWS EC2 instance in JavaScript](aws-js-webserver)
* [AWS EC2 instance in Python](aws-py-webserver)
* [Azure Virtual Machine in JavaScript](azure-js-webserver)
* [Kubernetes Nginx in TypeScript](kubernetes-ts-webserver)

An [extension of this example](aws-js-webserver-component/) demonstrates creating a minimal component that encapsulates
creating EC2 instances, highlighting one of the benefits of using general purpose languages for managing infrastructure.

### [Cloud-Agnostic URL Shortener](cloud-ts-url-shortener/)

Build a complete URL shortener web application using high-level `cloud.Table` and `cloud.HttpEndpoint` components. Highlights the ability to combine deployment time and runtime code, and the simple, cloud-agnostic, programming model of `@pulumi/cloud`. An [extension of this example](url-shortener-with-cache/) adds a reusable cache component to the URL shortener using `cloud.Service` to run a containerized Redis image.
This example demonstrates a complete URL shortener web application using high-level `cloud.Table` and
`cloud.HttpEndpoint` components, highlighting the ability to combine deployment time and runtime code, and the simple,
cloud-agnostic, programming model of `@pulumi/cloud`. Although we only support AWS today in this framework, our plan
is to offer an implementation of this on all major clouds, and so any code targeting this can truly run anywhere.

### [Web server](webserver/)
An [extension of this example](url-shortener-with-cache/) adds a reusable cache component to the URL shortener
using `cloud.Service` to run a containerized Redis image. This shows that you can create your own `cloud.*`-like
abstractions for your own use, your team's, or to share with the community using your language's package manager.

Deploy an EC2 instance using `@pulumi/aws`. An [extension of this example](webserver-component/) extracts out a webserver-component/ for creating EC2 instances, highlighting one of the benefits of using a general purpose language for managing infrastructure.
## [AWS Video Thumbnailer](aws-js-video-thumbnailer/)

### [Video thumbnailer](video-thumbnailer/)
This example features an end-to-end pipeline for generating keyframe thumbnails from videos uploaded to a bucket using
containerized [FFmpeg](https://www.ffmpeg.org/). It combines containers, serverless functions, and cloud storage into
a single 40-line application using `@pulumi/cloud-aws`.

Create an end-to-end pipleine for generating keyframe thumbnails from videos uploaded to a bucket using containerized [FFmpeg](https://www.ffmpeg.org/). Combines containers, serverless functions, and cloud storage into a single 40-line application using `@pulumi/cloud-aws`.
### [Raw AWS Serverless](aws-js-serverless-raw/)

### [Serverless raw](serverless-raw/)
This example deploys a complete serverless C# application using raw `aws.apigateway.RestAPI`, `aws.lambda.Function` and
`aws.dynamodb.Table` resources from `@pulumi/aws`. Although this doesn't feature any of the higher-level abstractions
from the `@pulumi/cloud` package, it demonstrates that you can program the raw resources directly available in AWS
to accomplish all of the same things this higher-level package offers.

Deploy a complete serverless C# application using raw `aws.apigateway.RestAPI`, `aws.lambda.Function` and `aws.dynamodb.Table` resources from `@pulumi/aws`. The deployed Lambda function is a simple C# application, highlighting the ability to manage existing application code in a Pulumi application.
The deployed Lambda function is a simple C# application, highlighting the ability to manage existing application code
in a Pulumi application, even if your Pulumi code is written in a different language like JavaScript or Python.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions aws-py-webserver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.pulumi/
*.pyc
7 changes: 7 additions & 0 deletions aws-py-webserver/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: webserver-py
runtime: python
description: Basic example of an AWS web server accessible over HTTP (in Python!)
stacks:
test-stack:
config:
aws:region: us-west-2
7 changes: 7 additions & 0 deletions aws-py-webserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# examples/scenarios/aws/webserver-py

An example based on the basic Amazon EC2 Instance sample at:
http:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/deploying.applications.html.

This is written in Python. A JavaScript version is available at examples/scenarios/aws/webserver/.

20 changes: 20 additions & 0 deletions aws-py-webserver/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2016-2018, Pulumi Corporation. All rights reserved.

import pulumi
from pulumi_aws import ec2
from ami import get_linux_ami

size = 't2.micro'

group = ec2.SecurityGroup('web-secgrp',
description='Enable HTTP access',
ingress=[
{ 'protocol': 'tcp', 'from_port': 80, 'to_port': 80, 'cidr_blocks': ['0.0.0.0/0'] }
])
server = ec2.Instance('web-server-www',
instance_type=size,
security_groups=[group.name],
ami=get_linux_ami(size))

pulumi.output('public_ip', server.public_ip)
pulumi.output('public_dns', server.public_dns)
150 changes: 150 additions & 0 deletions aws-py-webserver/ami.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Copyright 2016-2017, Pulumi Corporation. All rights reserved.

from pulumi_aws import config

# This file defines some maps that correspond to the recommended AWS Marketplace values:
# http:https://docs.aws.amazon.com/servicecatalog/latest/adminguide/catalogs_marketplace-products.html
# Ultimately, this lets us choose a recommended Amazon Linux AMI; see:
# https://aws.amazon.com/amazon-linux-ami/instance-type-matrix/

instance_type_arch = {
't1.micro' : 'PV64' ,
't2.nano' : 'HVM64',
't2.micro' : 'HVM64',
't2.small' : 'HVM64',
't2.medium' : 'HVM64',
't2.large' : 'HVM64',
'm1.small' : 'PV64' ,
'm1.medium' : 'PV64' ,
'm1.large' : 'PV64' ,
'm1.xlarge' : 'PV64' ,
'm2.xlarge' : 'PV64' ,
'm2.2xlarge' : 'PV64' ,
'm2.4xlarge' : 'PV64' ,
'm3.medium' : 'HVM64',
'm3.large' : 'HVM64',
'm3.xlarge' : 'HVM64',
'm3.2xlarge' : 'HVM64',
'm4.large' : 'HVM64',
'm4.xlarge' : 'HVM64',
'm4.2xlarge' : 'HVM64',
'm4.4xlarge' : 'HVM64',
'm4.10xlarge': 'HVM64',
'c1.medium' : 'PV64' ,
'c1.xlarge' : 'PV64' ,
'c3.large' : 'HVM64',
'c3.xlarge' : 'HVM64',
'c3.2xlarge' : 'HVM64',
'c3.4xlarge' : 'HVM64',
'c3.8xlarge' : 'HVM64',
'c4.large' : 'HVM64',
'c4.xlarge' : 'HVM64',
'c4.2xlarge' : 'HVM64',
'c4.4xlarge' : 'HVM64',
'c4.8xlarge' : 'HVM64',
'g2.2xlarge' : 'HVMG2',
'g2.8xlarge' : 'HVMG2',
'r3.large' : 'HVM64',
'r3.xlarge' : 'HVM64',
'r3.2xlarge' : 'HVM64',
'r3.4xlarge' : 'HVM64',
'r3.8xlarge' : 'HVM64',
'i2.xlarge' : 'HVM64',
'i2.2xlarge' : 'HVM64',
'i2.4xlarge' : 'HVM64',
'i2.8xlarge' : 'HVM64',
'd2.xlarge' : 'HVM64',
'd2.2xlarge' : 'HVM64',
'd2.4xlarge' : 'HVM64',
'd2.8xlarge' : 'HVM64',
'hi1.4xlarge': 'HVM64',
'hs1.8xlarge': 'HVM64',
'cr1.8xlarge': 'HVM64',
'cc2.8xlarge': 'HVM64',
}
"""A map of instance type to its architecture."""

region_arch_linux_ami = {
'us-east-1': {
'PV64' : 'ami-2a69aa47',
'HVM64': 'ami-6869aa05',
'HVMG2': 'ami-648d9973',
},
'us-west-2': {
'PV64' : 'ami-7f77b31f',
'HVM64': 'ami-7172b611',
'HVMG2': 'ami-09cd7a69',
},
'us-west-1': {
'PV64' : 'ami-a2490dc2',
'HVM64': 'ami-31490d51',
'HVMG2': 'ami-1e5f0e7e',
},
'eu-west-1': {
'PV64' : 'ami-4cdd453f',
'HVM64': 'ami-f9dd458a',
'HVMG2': 'ami-b4694ac7',
},
'eu-west-2': {
'PV64' : 'NOT_SUPPORTED',
'HVM64': 'ami-886369ec',
'HVMG2': 'NOT_SUPPORTED',
},
'eu-central-1': {
'PV64' : 'ami-6527cf0a',
'HVM64': 'ami-ea26ce85',
'HVMG2': 'ami-de5191b1',
},
'ap-northeast-1': {
'PV64' : 'ami-3e42b65f',
'HVM64': 'ami-374db956',
'HVMG2': 'ami-df9ff4b8',
},
'ap-northeast-2': {
'PV64' : 'NOT_SUPPORTED',
'HVM64': 'ami-2b408b45',
'HVMG2': 'NOT_SUPPORTED',
},
'ap-southeast-1': {
'PV64' : 'ami-df9e4cbc',
'HVM64': 'ami-a59b49c6',
'HVMG2': 'ami-8d8d23ee',
},
'ap-southeast-2': {
'PV64' : 'ami-63351d00',
'HVM64': 'ami-dc361ebf',
'HVMG2': 'ami-cbaf94a8',
},
'ap-south-1': {
'PV64' : 'NOT_SUPPORTED',
'HVM64': 'ami-ffbdd790',
'HVMG2': 'ami-decdbab1',
},
'us-east-2': {
'PV64' : 'NOT_SUPPORTED',
'HVM64': 'ami-f6035893',
'HVMG2': 'NOT_SUPPORTED',
},
'ca-central-1': {
'PV64' : 'NOT_SUPPORTED',
'HVM64': 'ami-730ebd17',
'HVMG2': 'NOT_SUPPORTED',
},
'sa-east-1': {
'PV64' : 'ami-1ad34676',
'HVM64': 'ami-6dd04501',
'HVMG2': 'NOT_SUPPORTED',
},
'cn-north-1': {
'PV64' : 'ami-77559f1a',
'HVM64': 'ami-8e6aa0e3',
'HVMG2': 'NOT_SUPPORTED',
}
}
"""A map from region to inner maps from architecture to the recommended Linux AMI."""

def get_linux_ami(instance_type):
"""Gets the recommended Linux AMI for the given instance in the current AWS region."""
region = config.region
arch = instance_type_arch[instance_type]
return region_arch_linux_ami[region][arch]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
2 changes: 2 additions & 0 deletions kubernetes-ts-guestbook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/node_modules/
4 changes: 4 additions & 0 deletions kubernetes-ts-guestbook/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: guestbook
runtime: nodejs
description: Kubernetes Guestbook example based on https://kubernetes.io/docs/tutorials/stateless-application/guestbook/

Loading

0 comments on commit 2398e57

Please sign in to comment.