🚀 Serverless Fargate
Adds the ability to maintain long-running Fargate ECS tasks within your Serverless project.
Overview
Not all behaviour can be broken down and modelled within Lambda's execution duration constraints.
Sometimes you need the ability to exceed this duration, but wish to remain in a Serverless environment.
This plugin adds the ability to declare Fargate-backed ECS tasks which are provisioned during a Serverless deployment.
Taking advantage of Serverless Frameworks ability to build/push images to ECR, you are able to declare both long-running and Lambda-based behaviour side-by-side.
At a high-level the plugin provides the following functionality:
- Allows you to declare service-based (continuous) and scheduled tasks.
- Uses the ECR image support provided within Serverless Framework to help build tasks.
- Maintains an IAM role which honours all managed policies and statements that have been declared within the provider configuration.
- Provides escape-hatches to supply custom configuration such as role ARNs/tags etc.
- Handles both Fargate and Fargate Spot execution environments.
Example
Below is an example configuration which highlights all possible available options.
provider:
ecr:
images:
my-task:
path: ./
file: Dockerfile
iamRoleStatements:
- Effect: Allow
Action: 'sqs:*'
Resource: '*'
iamManagedPolicies:
- arn:aws:iam::123456:policy/my-managed-provider-policy
environment:
name: value
vpc:
securityGroupIds:
- sg-12345
subnetIds:
- subnet-1234
tags:
name: value
fargate:
clusterName: my-cluster-name
containerInsights: true
memory: '0.5GB'
cpu: 256
architecture: X86_64
environment:
name: value
logGroupName: my-cluster-log-group
logRetentionInDays: 365
executionRoleArn: arn:aws:iam::123456:role/my-custom-execution-role
taskRoleArn: arn:aws:iam::123456:role/my-custom-task-role
iamRoleStatements:
- Effect: Allow
Action: 'resource:*'
Resource: '*'
iamManagedPolicies:
- arn:aws:iam::123456:policy/my-managed-task-policy
vpc:
securityGroupIds:
- sg-12345
subnetIds:
- subnet-1234
assignPublicIp: false
tags:
name: value
cloudFormationResource:
task:
EphemeralStorage: 5
container:
StopTimeout: 5
additionalContainers:
- Name: 'additional-container-name'
Image: 'additional-container-image'
service:
EnableECSManagedTags: 'true'
tasks:
my-task:
name: my-task-name
image: my-task
executionRoleArn: arn:aws:iam::123456:role/my-custom-execution-role
taskRoleArn: arn:aws:iam::123456:role/my-custom-task-role
vpc:
securityGroupIds:
- sg-12345
subnetIds:
- subnet-1234
assignPublicIp: false
command:
- my-command
entryPoint:
- my-entrypoint
memory: '0.5GB'
cpu: 256
architecture: ARM64
environment:
name: value
tags:
name: value
dependsOn: ['MyExampleResource']
service:
desiredCount: 1
maximumPercent: 200
minimumHealthyPercent: 100
spot: false
schedule: 'rate(1 minute)'
cloudFormationResource:
task:
EphemeralStorage: 5
container:
StopTimeout: 5
additionalContainers:
- Name: 'additional-container-name'
Image: 'additional-container-image'
service:
EnableECSManagedTags: 'true'
Inspired by https://github.com/svdgraaf/serverless-fargate-tasks