[[AWS Fargate|Fargate]] integrates pretty tightly with [[AWS Step Functions|Step Functions]] and is a great pairing if you have a workload which requires running an on-demand job for which [[AWS Lambda|Lambda]] would not be a good fit (e.g. it's long-running job).
You can launch a Fargate task from a StateMachine state ([see docs](https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html)) without going via Lambda.
The nice thing about using StepFunctions with containers is that it gives you automatic error and retry handling if your container fails. It also allows you to add additional logic for your use case using Lambda functions (which tend to be easier to author and deploy) rather than having to add changes to your container. A general principle I like to follow is to keep the responsibility of the container to a minimum.
## Passing parameters into your container
In order to pass parameters into your container, there are two ways to do this.
- command line arguments top the container entrypoint
- environment variables
The following example shows how these could be supplied to your state machine (see the `ContainerOverrides` section):
```yml
RunScreamingFrogContainer:
Type: Task
Resource: arn:aws:states:::ecs:runTask.sync
Parameters:
LaunchType: FARGATE
Cluster: ${cf:${self:custom.fargateClusterStackName}.Cluster}
TaskDefinition: !Ref ScreamingFrogTask
NetworkConfiguration:
AwsvpcConfiguration:
Subnets:
- ${cf:${self:custom.vpcStackName}.SubnetAPublic}
- ${cf:${self:custom.vpcStackName}.SubnetBPublic}
AssignPublicIp: ENABLED
SecurityGroups:
- !Ref ServiceSecurityGroup
Overrides:
ContainerOverrides:
- Name: app
'Command.