aws-native logo
AWS Native v0.64.0, Jun 2 23

Create an ECS cluster on AWS with the AWS Native Provider | TypeScript

View Code Deploy

Create an ECS cluster, and deploy a task and service.

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.

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 dev
  2. Set the AWS region:

    Either using an environment variable

    $ export AWS_REGION=us-west-2

    Or with the stack config

    $ pulumi config set aws:region us-west-2
    $ pulumi config set aws-native:region us-west-2
  3. Restore NPM modules via npm install or yarn install.

  4. Run pulumi up to preview and deploy changes. After the preview is shown you will be prompted if you want to continue or not.

    $ pulumi up
    Previewing update (dev)
    Updating (dev)
    View Live:***/aws-native-ts-ecs/dev/updates/1
         Type                                           Name                   Status
    +   pulumi:pulumi:Stack                            aws-native-ts-ecs-dev  created
    +   ├─ aws:iam:Role                                task-exec-role         created
    +   ├─ aws-native:ecs:Cluster                      cluster                created
    +   ├─ aws:lb:TargetGroup                          app-tg                 created
    +   ├─ aws:ec2:SecurityGroup                       web-secgrp             created
    +   ├─ aws:iam:RolePolicyAttachment                task-exec-policy       created
    +   ├─ aws-native:ecs:TaskDefinition               app-task               created
    +   ├─ aws:lb:LoadBalancer                         app-lb                 created
    +   ├─ aws-native:elasticloadbalancingv2:Listener  web                    created
    +   └─ aws-native:ecs:Service                      app-svc                created
    url: "app-lb-***"
    + 10 created
    Duration: ***
  5. To see the resources that were created, run pulumi stack output:

    $ pulumi stack output
    Current stack outputs (1):
    url     app-lb-***
  6. Use curl to confirm that NGINX was deployed successfully:

    $ curl $(pulumi stack output url)
    <!DOCTYPE html>
    <title>Welcome to nginx!</title>
    html { color-scheme: light dark; }
    body { width: 35em; margin: 0 auto;
    font-family: Tahoma, Verdana, Arial, sans-serif; }
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    <p>For online documentation and support please refer to
    <a href=""></a>.<br/>
    Commercial support is available at
    <a href=""></a>.</p>
    <p><em>Thank you for using nginx.</em></p>
  7. To clean up resources, run pulumi destroy and answer the confirmation question at the prompt.