Add aws-native ECS example
ADD
aws-native-ts-ecs/.gitignore
+/bin/
+/node_modules/

ADD
aws-native-ts-ecs/Pulumi.yaml
+name: aws-native-ts-ecs
+runtime: nodejs
+description: A TypeScript Pulumi program with AWS Native provider that provisions an ECS Cluster

ADD
aws-native-ts-ecs/classic.ts
+// Copyright 2016-2021, Pulumi Corporation.
+
+import * as aws from "@pulumi/aws";
+import * as pulumi from "@pulumi/pulumi";
+
+// Note: Some resources are not yet supported by the Native AWS provider, so we are using both the Native
+// and Classic provider in this example. The resources will be updated to use native resources as they are
+// available in AWS's Cloud Control API.
+
+const defaultVpc = pulumi.output(aws.ec2.getVpc({default: true}));
+const defaultVpcSubnets = defaultVpc.id.apply(id => aws.ec2.getSubnetIds({vpcId: id}));
+
+const group = new aws.ec2.SecurityGroup("web-secgrp", {
+ vpcId: defaultVpc.id,
+ description: "Enable HTTP access",
+ ingress: [{
+ protocol: "tcp",
+ fromPort: 80,
+ toPort: 80,
+ cidrBlocks: ["0.0.0.0/0"],
+ }],
+ egress: [{
+ protocol: "-1",
+ fromPort: 0,
+ toPort: 0,
+ cidrBlocks: ["0.0.0.0/0"],
+ }],
+});
+
+const alb = new aws.lb.LoadBalancer("app-lb", {
+ securityGroups: [group.id],
+ subnets: defaultVpcSubnets.ids,
+});
+
+const atg = new aws.lb.TargetGroup("app-tg", {
+ port: 80,
+ protocol: "HTTP",
+ targetType: "ip",
+ vpcId: defaultVpc.id,
+});
+
+const role = new aws.iam.Role("task-exec-role", {
+ assumeRolePolicy: {
+ Version: "2008-10-17",
+ Statement: [{
+ Sid: "",
+ Effect: "Allow",
+ Principal: {
+ Service: "ecs-tasks.amazonaws.com",
+ },
+ Action: "sts:AssumeRole",
+ }],
+ },
+});
+
+const rpa = new aws.iam.RolePolicyAttachment("task-exec-policy", {
+ role: role.name,
+ policyArn: "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy",
+});
+
+export const albArn = alb.arn;
+export const albDnsName = alb.dnsName;
+export const atgArn = atg.arn;
+export const roleArn = role.arn;
+export const subnetIds = defaultVpcSubnets.ids;
+export const securityGroupId = group.id;

ADD
aws-native-ts-ecs/index.ts
+// Copyright 2016-2021, Pulumi Corporation.
+
+import * as awsnative from "@pulumi/aws-native";
+import * as classic from "./classic";
+
+const cluster = new awsnative.ecs.Cluster("cluster", {
+ clusterName: "cloud-api-cluster",
+});
+
+const wl = new awsnative.elasticloadbalancingv2.Listener("web", {
+ loadBalancerArn: classic.albArn,
+ port: 80,
+ protocol: "HTTP",
+ defaultActions: [{
+ type: "forward",
+ targetGroupArn: classic.atgArn,
+ }],
+});
+
+const taskDefinition = new awsnative.ecs.TaskDefinition("app-task", {
+ family: "fargate-task-definition",
+ cpu: "256",
+ memory: "512",
+ networkMode: "awsvpc",
+ requiresCompatibilities: ["FARGATE"],
+ executionRoleArn: classic.roleArn,
+ containerDefinitions: [{
+ name: "my-app",
+ image: "nginx",
+ portMappings: [{
+ containerPort: 80,
+ hostPort: 80,
+ protocol: "tcp",
+ }],
+ }],
+});
+
+const service = new awsnative.ecs.Service("app-svc", {
+ serviceName: "app-svc-cloud-api",
+ cluster: cluster.arn,
+ desiredCount: 1,
+ launchType: "FARGATE",
+ taskDefinition: taskDefinition.taskDefinitionArn,
+ networkConfiguration: {
+ awsvpcConfiguration: {
+ assignPublicIp: "ENABLED",
+ subnets: classic.subnetIds,
+ securityGroups: [classic.securityGroupId],
+ },
+ },
+ loadBalancers: [{
+ targetGroupArn: classic.atgArn,
+ containerName: "my-app",
+ containerPort: 80,
+ }],
+}, {dependsOn: [wl]});
+
+export const url = classic.albDnsName;

ADD
aws-native-ts-ecs/package.json
+{
+ "name": "aws-native-ts-ecs",
+ "devDependencies": {
+ "@types/node": "^8.0.0"
+ },
+ "dependencies": {
+ "@pulumi/aws": "^4.0.0",
+ "@pulumi/aws-native": "^0.1.0",
+ "@pulumi/pulumi": "^3.0.0"
+ }
+}

ADD
aws-native-ts-ecs/tsconfig.json
+{
+ "compilerOptions": {
+ "strict": true,
+ "outDir": "bin",
+ "target": "es2016",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true
+ },
+ "files": [
+ "index.ts",
+ "classic.ts"
+ ]
+}

MODIFY
aws-native-ts-s3-folder/README.md
aws-native-ts-s3-folder/README.md
A static website that uses [S3's website support](https://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteHosting.html).
For a detailed walkthrough of this example, see the tutorial [Static Website on AWS S3](https://www.pulumi.com/docs/tutorials/aws/s3-website/).
-Note: Some of the resources are not yet supported by the Native AWS provider, so we are using both the Native
+Note: Some resources are not yet supported by the Native AWS provider, so we are using both the Native
and Classic provider in this example. The resources will be updated to use native resources as they are
available in AWS's Cloud Control API.

MODIFY
aws-native-ts-s3-folder/index.ts
aws-native-ts-s3-folder/index.ts
import * as aws from "@pulumi/aws";
import * as awsnative from "@pulumi/aws-native";
import * as pulumi from "@pulumi/pulumi";
-import * as fs from 'fs';
+import * as fs from "fs";
import * as mime from "mime";
// Create a bucket and expose a website index document

Add aws-native ECS example (#1086)