forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using awsinfra for several examples. (pulumi#206)
This better shows how to create an ecs Service that is fully under the control of the user.
- Loading branch information
1 parent
71225e5
commit e3dd441
Showing
20 changed files
with
606 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: container-quickstart | ||
description: NGINX container example | ||
runtime: nodejs | ||
template: | ||
config: | ||
aws:region: | ||
description: The AWS region to deploy into | ||
default: us-west-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# Easy container example | ||
|
||
Companion to the tutorial [Provision containers on AWS](https://pulumi.io/quickstart/aws-containers.html). | ||
|
||
## Prerequisites | ||
|
||
To run this example, make sure [Docker](https://docs.docker.com/engine/installation/) is installed and running. | ||
|
||
## Running the App | ||
|
||
Note: some values in this example will be different from run to run. These values are indicated | ||
with `***`. | ||
|
||
1. Create a new stack: | ||
|
||
``` | ||
$ pulumi stack init containers-dev | ||
``` | ||
1. Configure Pulumi to use an AWS region that supports Fargate. This is currently only available in `us-east-1`, `us-east-2`, `us-west-2`, and `eu-west-1`: | ||
``` | ||
$ pulumi config set aws:region us-west-2 | ||
``` | ||
1. Restore NPM modules via `npm install` or `yarn install`. | ||
1. Preview and deploy the app via `pulumi up`. The preview will take a few minutes, as it builds a Docker container. A total of 19 resources are created. | ||
``` | ||
$ pulumi up | ||
``` | ||
1. View the endpoint URL, and run curl: | ||
```bash | ||
$ pulumi stack output | ||
Current stack outputs (1) | ||
OUTPUT VALUE | ||
hostname http://***.elb.us-west-2.amazonaws.com | ||
$ curl $(pulumi stack output hostname) | ||
<html> | ||
<head><meta charset="UTF-8"> | ||
<title>Hello, Pulumi!</title></head> | ||
<body> | ||
<p>Hello, S3!</p> | ||
<p>Made with ❤️ with <a href="https://pulumi.com">Pulumi</a></p> | ||
</body></html> | ||
``` | ||
1. To view the runtime logs from the container, use the `pulumi logs` command. To get a log stream, use `pulumi logs --follow`. | ||
``` | ||
$ pulumi logs --follow | ||
Collecting logs for stack container-quickstart-dev since 2018-05-22T14:25:46.000-07:00. | ||
2018-05-22T15:33:22.057-07:00[ pulumi-nginx] 172.31.13.248 - - [22/May/2018:22:33:22 +0000] "GET / HTTP/1.1" 200 189 "-" "curl/7.54.0" "-" | ||
``` | ||
## Clean up | ||
To clean up resources, run `pulumi destroy` and answer the confirmation question at the prompt. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM nginx | ||
COPY content /usr/share/nginx/html |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head><meta charset="UTF-8"> | ||
<title>Hello, Pulumi!</title></head> | ||
<body> | ||
<p>Hello, containers!</p> | ||
<p>Made with ❤️ with <a href="https://pulumi.com">Pulumi</a></p> | ||
</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const awsx = require("@pulumi/aws-infra"); | ||
|
||
let cluster = new awsx.ecs.Cluster("example", { }); | ||
let listener= new awsx.elasticloadbalancingv2.NetworkListener("nginx", { port: 80 }); | ||
let service = new awsx.ecs.FargateService("nginx", { | ||
cluster, | ||
desiredCount: 2, | ||
taskDefinitionArgs: { | ||
containers: { | ||
nginx: { | ||
image: awsx.ecs.Image.fromPath("./app"), | ||
memory: 512, | ||
portMappings: [listener], | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// export just the hostname property of the container frontend | ||
exports.hostname = listener.endpoint().apply(e => `http://${e.hostname}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "container-quickstart", | ||
"main": "index.js", | ||
"dependencies": { | ||
"@pulumi/pulumi": "dev", | ||
"@pulumi/aws": "dev", | ||
"@pulumi/aws-infra": "dev" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: url-shortener-cache-http | ||
runtime: nodejs | ||
description: URL shortener with cache and HttpServer | ||
template: | ||
config: | ||
aws:region: | ||
description: The AWS region to deploy into | ||
default: us-west-2 | ||
cloud:provider: | ||
description: The cloud provider | ||
default: aws | ||
cloud-aws:useFargate: | ||
description: Whether to use Fargate-based container compute | ||
default: true | ||
cloud-aws:functionIncludePaths: | ||
description: Directory to include with the uploaded function code | ||
default: www | ||
redisPassword: | ||
description: The Redis password | ||
secret: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# Serverless URL Shortener with Redis Cache and HttpServer | ||
|
||
A sample URL shortener SPA that uses the high-level components. The example shows to combine serverless functions along with containers. This shows that you can create your own higher level | ||
abstractions for your own use, your team's, or to share with the community using your language's package manager. | ||
|
||
## Deploying and running the program | ||
|
||
Note: some values in this example will be different from run to run. These values are indicated | ||
with `***`. | ||
|
||
1. Create a new stack: | ||
|
||
``` | ||
$ pulumi stack init url-cache-testing | ||
``` | ||
1. Configure Pulumi to use an AWS region that supports Fargate, which is currently only available in `us-east-1`, `us-east-2`, `us-west-2`, and `eu-west-1`: | ||
``` | ||
$ pulumi config set aws:region us-west-2 | ||
``` | ||
1. Set a value for the Redis password. The value can be an encrypted secret, specified with the `--secret` flag. If this flag is not provided, the value will be saved as plaintext in `Pulumi.url-cache-testing.yaml` (since `url-cache-testing` is the current stack name). | ||
``` | ||
$ pulumi config set --secret redisPassword S3cr37Password | ||
``` | ||
1. Add the 'www' directory to the uploaded function code so it can be served from the http server: | ||
``` | ||
$ pulumi config set cloud-aws:functionIncludePaths www | ||
``` | ||
1. Restore NPM modules via `npm install` or `yarn install`. | ||
1. Compile the program via `tsc` or `npm run build` or `yarn run build`. | ||
1. Preview and run the deployment via `pulumi update`. The operation will take about 5 minutes to complete. | ||
``` | ||
$ pulumi update | ||
Previewing stack 'url-cache-testing' | ||
... | ||
Updating stack 'url-cache-testing' | ||
Performing changes: | ||
#: Resource Type Name | ||
1: pulumi:pulumi:Stack url-shortener-cache-url- | ||
... | ||
49: aws:apigateway:Stage urlshortener | ||
info: 49 changes performed: | ||
+ 49 resources created | ||
Update duration: *** | ||
``` | ||
1. To view the API endpoint, use the `stack output` command: | ||
``` | ||
$ pulumi stack output endpointUrl | ||
https://***.us-east-1.amazonaws.com/stage/ | ||
``` | ||
1. Open this page in a browser and you'll see a single page app for creating and viewing short URLs. | ||
## Clean up | ||
To clean up resources, run `pulumi destroy` and answer the confirmation question at the prompt. |
Oops, something went wrong.