copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

Empty ECS Clusters being created to deploy just Static Site service

Open davivcgarcia opened this issue 2 years ago • 2 comments

Explanation

The copilot init command creates a empty environment (Amazon ECS cluster and other shared resources) even if the user selects the workload type as Static Site, which should rely only on Amazon S3 and Amazon Cloudfront. The ECS cluster is completely empty, without any ECS Task or Service deployed, and should only be created if necessary.

Outputs

$ copilot init                                       
Welcome to the Copilot CLI! We're going to walk you through some questions
to help you get set up with a containerized application on AWS. An application is a collection of
containerized services that operate together.

Application name: demo
Workload type: Static Site
Service name: frontend
Custom Path to Source: src/frontend
Another: No
Ok great, we'll set up a Static Site named frontend in application demo.

✔ Proposing infrastructure changes for stack demo-infrastructure-roles
- Creating the infrastructure for stack demo-infrastructure-roles                               [create complete]  [46.9s]
  - A StackSet admin role assumed by CloudFormation to manage regional stacks                   [create complete]  [17.3s]
  - An IAM role assumed by the admin role to create ECR repositories, KMS keys, and S3 buckets  [create complete]  [20.6s]
✔ The directory copilot will hold service manifests for application demo.

Note: Architecture type arm64 has been detected. We will set platform 'linux/x86_64' instead. If you'd rather build and run as architecture type arm64, please change the 'platform' field in your workload manifest to 'linux/arm64'.
✔ Wrote the manifest for service frontend at copilot/frontend/manifest.yml
Your manifest contains configurations like your container size and port.

- Update regional resources with stack set "demo-infrastructure"  [succeeded]  [0.0s]
All right, you're all set for local development.
Deploy: Yes
Only found one option, defaulting to: Create a new environment
Environment name: development
Environment development does not yet exist in application demo; initializing it.
✔ Wrote the manifest for environment development at copilot/environments/development/manifest.yml
- Update regional resources with stack set "demo-infrastructure"  [succeeded]  [0.0s]
- Update regional resources with stack set "demo-infrastructure"  [succeeded]        [125.1s]
  - Update resources in region "eu-central-1"                     [create complete]  [125.4s]
    - KMS key to encrypt pipeline artifacts between stages        [create complete]  [121.6s]
    - S3 Bucket to store local artifacts                          [create complete]  [1.5s]
✔ Proposing infrastructure changes for the demo-development environment.
- Creating the infrastructure for the demo-development environment.  [create complete]  [51.7s]
  - An IAM Role for AWS CloudFormation to manage resources           [create complete]  [26.4s]
  - An IAM Role to describe resources in your environment            [create complete]  [22.3s]
✔ Provisioned bootstrap resources for environment development in region eu-central-1 under application demo.
✔ Provisioned bootstrap resources for environment development.
✔ Proposing infrastructure changes for the demo-development environment.
- Creating the infrastructure for the demo-development environment.                    [update complete]  [203.9s]
  - An ECS cluster to group your services                                              [create complete]  [3.8s]
  - A security group to allow your containers to talk to each other                    [create complete]  [0.0s]
  - An Internet Gateway to connect to the public internet                              [create complete]  [17.3s]
  - A resource policy to allow AWS services to create log streams for your workloads.  [create complete]  [0.0s]
  - Private subnet 1 for resources with no internet access                             [create complete]  [0.0s]
  - Private subnet 2 for resources with no internet access                             [create complete]  [0.0s]
  - A custom route table that directs network traffic for the public subnets           [create complete]  [11.3s]
  - Public subnet 1 for resources that can access the internet                         [create complete]  [0.0s]
  - Public subnet 2 for resources that can access the internet                         [create complete]  [3.4s]
  - A private DNS namespace for discovering services within the environment            [create complete]  [43.3s]
  - A Virtual Private Cloud to control networking of your AWS resources                [create complete]  [10.0s]
✔ Proposing infrastructure changes for stack demo-development-frontend
- Creating the infrastructure for stack demo-development-frontend                           [create complete]  [583.2s]
  - A bucket policy to grant CloudFront read access to the Static Site bucket               [create complete]  [0.0s]
  - An S3 Bucket to store the static site's assets                                          [create complete]  [23.8s]
  - A CloudFront distribution for global content delivery                                   [create complete]  [505.4s]
  - Access control to make the content in the S3 bucket only accessible through CloudFront  [create complete]  [0.0s]
  - CloudFront Function to rewrite viewer request to index.html                             [create complete]  [0.0s]
  - An IAM Role for the state machine that moves source files to the S3 bucket              [create complete]  [17.9s]
  - A state machine that moves source files to the S3 bucket                                [create complete]  [0.0s]
  - A policy that gives the Env Manager role access to this site's S3 Bucket                [create complete]  [15.7s]
  - A custom resource that starts the process of moving files to the S3 bucket              [create complete]  [3.3s]
  - An IAM Role for the lambda that starts the process of moving files to the S3 bucket     [create complete]  [21.6s]
  - A lambda that starts the process of moving files to the S3 bucket                       [create complete]  [8.3s]
✔ Deployed service frontend.
Recommended follow-up action:
  - You can access your service at https://d1so3oklyyy73y.cloudfront.net/ over the internet.
- Be a part of the Copilot ✨community✨!
  Ask or answer a question, submit a feature request...
  Visit 👉 https://aws.github.io/copilot-cli/community/get-involved/ to see how!

davivcgarcia avatar Oct 24 '23 17:10 davivcgarcia

Hi, @davivcgarcia!

Thanks for opening this issue. You're right-- now that Copilot supports non-ECS services, the ECS Cluster generated during environment creation can be extraneous. In general, we try to add only necessary resources.

For now, if you'd like to delete the cluster, you may use a YAML patch:

- op: remove
  path: /Resources/Cluster

huanjani avatar Oct 24 '23 19:10 huanjani

I thought this would be useful so I bookmarked this so I can test it.

It looks like you also have to remove /Outputs/ClusterId as well in the environment override, because is dependent on the Cluster.

I wonder if there are other resources that aren't required for an s3/cloudfront site to be deployed such as VPC and nat gateway. Having this as lean as possible would be great. It would be great to only include resources when the corresponding service requirements are added.

surrealchemist avatar Oct 02 '24 14:10 surrealchemist