aws / copilot-cli

The AWS Copilot CLI is a tool for developers to build, release and operate production ready containerized applications on AWS App Runner or Amazon ECS on AWS Fargate.
https://aws.github.io/copilot-cli/
Apache License 2.0
3.5k stars 408 forks source link

Automatically round up to nearest Fargate cpu/mem #2081

Open kohidave opened 3 years ago

kohidave commented 3 years ago

We should just automatically round up to the valid cpu and mem values in Fargate so even if someone enters an invalid mem/cpu combo it doesn't stop them from building and deploying.

camilosantana commented 3 years ago

in user-experience spirit, this may be related to https://github.com/aws/copilot-cli/issues/1625

camilosantana commented 3 years ago

to comment further on user experience, i ran into this vague error via:

copilot job init
# edit manifest
copilot job deploy

The manifest edit was where I introduced illegal values for fargate cpu units.

name: conntest
type: Scheduled Job

on:
  schedule: "@every 25m"
timeout: 30m

image:
  build: Dockerfile-conntest

cpu: 128 # Number of CPU units for the task.
memory: 256 # Amount of memory in MiB used by the task.

entrypoint: "./run-my-tests.py"

I was using tiny values because this is all that's in my Dockerfile

FROM alpine:3.2 AS builder

RUN apk update && apk upgrade && apk add curl wget bash jq netcat-openbsd

FROM builder AS deploy

COPY --from=builder /bin /bin
COPY --from=builder /usr /usr
COPY --from=builder /sbin /sbin

CMD ["/bin/ash"]

the subsequent deploy command yields this error:

Invalid request provided: Create TaskDefinition: 
No Fargate configuration exists for given values. 
(Service: AmazonECS; Status Code: 400;
Error Code: ClientException; 
Request ID: 3d7530c5-bfb4-6a4e-8a2a-53a3561b8f74;
Proxy: null)
camilosantana commented 3 years ago

for anyone finding this, valid values are here

CPU value Memory value (MiB)
256 (.25 vCPU) 512 (0.5GB), 1024 (1GB), 2048 (2GB)
512 (.5 vCPU) 1024 (1GB), 2048 (2GB), 3072 (3GB), 4096 (4GB)
1024 (1 vCPU) 2048 (2GB), 3072 (3GB), 4096 (4GB), 5120 (5GB), 6144 (6GB), 7168 (7GB), 8192 (8GB)
2048 (2 vCPU) Between 4096 (4GB) and 16384 (16GB) in increments of 1024 (1GB)
4096 (4 vCPU) Between 8192 (8GB) and 30720 (30GB) in increments of 1024 (1GB)

Note:

An error occurred (ClientException) when calling the RegisterTaskDefinition operation: 
Invalid 'cpu' setting for task. 
For more information, see the Troubleshooting section of the Amazon ECS Developer Guide.

is more helpful than

Error: ClientException: No Fargate configuration exists for given values.

I'm guessing the second error is being returned by the Go module being used here. In my opinion, returning a helpful error message is better than rounding up. Something like this that impacts cost, however trivial, should be made by the end user.

byF commented 3 years ago

@camilosantana you've just saved me, I had 1048 instead of 1024 as my CPU

We really need better manifest and CF validation, I keep running into these issues all the time.