eddmann / serverless-fargate

Maintain long-running Fargate ECS tasks within your Serverless project
53 stars 22 forks source link

Support for architecture configuration #38

Closed dimitor115 closed 1 year ago

dimitor115 commented 1 year ago

AFAIK the AWS ECS Fargate supports running tasks on ARM architecture. https://docs.aws.amazon.com/AmazonECS/latest/userguide/ecs-arm64.html

It would be awesome to be able to configure the desired architecture.

Shogan commented 1 year ago

I have just bumped into this myself funnily enough.

I'm on Apple Silicon M2 and attempted to get the underlying serverless docker ECR provisioner to build for platform linux/amd64 but didn't have any luck there (I tried setting my Dockerfile to use a linux/amd64 image, and set up fargate for this architecture too, but this plugin and serverless ECR seem to insist on forcing builds of arm64 because of my local machines architecture.

So what I've done is now configure the Fargate cluster to use ARM64, which is possible right now - you just need to set this at the task definition level. As long as Fargate is using platform version 1.4.0 or above you should be good.

My Dockerfile FROM directive:

FROM --platform=linux/arm64/v8 public.ecr.aws/docker/library/node:16-bullseye-slim

My serverless.yml definition for fargate:

fargate:
  memory: "2GB"
  cpu: 1024
  logGroupName: sample-task-fargate-logs
  tasks:
    sample-task-name:
      image: name-of-your-ecr-image
      architecture: ARM64
      schedule: "rate(1 day)"

plugins:
  - serverless-fargate

That's up and running for me now - my image builds as arm64 locally on my M2 system and in ECS Fargate it runs under ARM64 architecture too. If you inspect the task definition you'll see it's configured as expected with:

"runtimePlatform": {
    "cpuArchitecture": "ARM64"
}

Hope that helps!

eddmann commented 1 year ago

Thanks for the advice @Shogan, currently the plugin takes advantage of the inbuilt Serverless Framework ECR support.