Add a Docker on AWS Fargate example
ADD
aws-ts-hello-fargate/.gitignore
+/bin/
+/node_modules/

ADD
aws-ts-hello-fargate/Pulumi.yaml
+name: aws-ts-hello-fargate
+runtime: nodejs
+description: A minimal "Hello, World" container in Fargate.

ADD
aws-ts-hello-fargate/app/Dockerfile
+# Use an official Python runtime as a parent image
+FROM python:2.7-slim
+
+# Set the working directory to /app
+WORKDIR /app
+
+# Copy the current directory contents into the container at /app
+COPY . /app
+
+# Install any needed packages specified in requirements.txt
+RUN pip install --trusted-host pypi.python.org -r requirements.txt
+
+# Make port 80 available to the world outside this container
+EXPOSE 80
+
+# Define environment variable
+ENV NAME World
+
+# Run app.py when the container launches
+CMD ["python", "app.py"]

ADD
aws-ts-hello-fargate/app/app.py
+from flask import Flask
+from redis import Redis, RedisError
+import os
+import socket
+
+# Connect to Redis
+redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
+
+app = Flask(__name__)
+
+@app.route("/")
+def hello():
+ try:
+ visits = redis.incr("counter")
+ except RedisError:
+ visits = "<i>cannot connect to Redis, counter disabled</i>"
+
+ html = "<h3>Hello {name}!</h3>" \
+ "<b>Hostname:</b> {hostname}<br/>" \
+ "<b>Visits:</b> {visits}"
+ return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
+
+if __name__ == "__main__":
+ app.run(host='0.0.0.0', port=80)

ADD
aws-ts-hello-fargate/app/requirements.txt
+Flask
+Redis

ADD
aws-ts-hello-fargate/index.ts
+import * as awsx from "@pulumi/awsx";
+
+// Step 1: Create an ECS Fargate cluster.
+const cluster = new awsx.ecs.Cluster("cluster");
+
+// Step 2: Define the Networking for our service.
+const alb = new awsx.elasticloadbalancingv2.ApplicationLoadBalancer(
+ "net-lb", { external: true, securityGroups: cluster.securityGroups });
+const web = alb.createListener("web", { port: 80, external: true });
+
+// Step 3: Build and publish a Docker image to a private ECR registry.
+const img = awsx.ecs.Image.fromPath("app-img", "./app");
+
+// Step 4: Create a Fargate service task that can scale out.
+const appService = new awsx.ecs.FargateService("app-svc", {
+ cluster,
+ taskDefinitionArgs: {
+ container: {
+ image: img,
+ cpu: 102 /*10% of 1024*/,
+ memory: 50 /*MB*/,
+ portMappings: [ web ],
+ },
+ },
+ desiredCount: 5,
+});
+
+// Step 5: Export the Internet address for the service.
+export const url = web.endpoint.hostname;

ADD
aws-ts-hello-fargate/package.json
+{
+ "name": "aws-typescript",
+ "devDependencies": {
+ "@types/node": "latest"
+ },
+ "dependencies": {
+ "@pulumi/aws": "latest",
+ "@pulumi/awsx": "^0.18.3",
+ "@pulumi/docker": "^0.17.0",
+ "@pulumi/pulumi": "latest"
+ }
+}

ADD
aws-ts-hello-fargate/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es6",
+ "lib": [
+ "es6"
+ ],
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true,
+ "strictNullChecks": true
+ },
+ "files": [
+ "index.ts"
+ ]
+}

Add a Docker on AWS Fargate example (#290)