Write containerOverwrites from Lambda to Container
Hello All
I have a step function that is calling a lambda, which does some processing, and gets the id of the job that needs to be processed by the ecs runtask.
What I am trying to do is to pass the job Id as containerOverride so that each run a different Id can be passed to the ecs Run task.
Here is the dummy lambda Output:
Test Event Name
dummyTest
Response
{
"containerOverrides": " [ { \"name\": \"getFileTask\", \"environment\": [ { \"name\": \"name1\", \"value\": \"123\" }, { \"name\": \"DATE\", \"value\": \"1234-12-12\" }, { \"name\": \"SCRIPT\", \"value\": \"123456\" } ] } ] "
}
Dummy Lambda Code:
def lambda_handler(event, context):
# TODO implement
print("Success")
overridden_Text = ' [ { "name": "getFileTask", "environment": [ { "name": "name1", "value": "123" }, { "name": "DATE", "value": "1234-12-12" }, { "name": "SCRIPT", "value": "123456" } ] } ] '
return{
'containerOverrides': overridden_Text
}
Here is the record when the ECS run task is triggered(TaskStateEntered) from the step function:
{
"name": "ECS RunTask",
"input": {
"containerOverrides": " [ { \"name\": \"getFileTask\", \"environment\": [ { \"name\": \"name1\", \"value\": \"123\" }, { \"name\": \"DATE\", \"value\": \"1234-12-12\" }, { \"name\": \"SCRIPT\", \"value\": \"123456\" } ] } ] "
},
"inputDetails": {
"truncated": false
}
}
The issue is that when the run task enters the TaskSubmitted stage:
"LastStatus": "PROVISIONING",
"LaunchType": "FARGATE",
"Memory": "4096",
"Overrides": {
"ContainerOverrides": [
{
"Command": [],
"Environment": [],
"EnvironmentFiles": [],
"Name": "getFileTask",
"ResourceRequirements": []
}
],
"InferenceAcceleratorOverrides": []
},
"PlatformFamily": "Linux",
"PlatformVersion": "1.4.0",
"StartedBy": "AWS Step Functions",
For what ever reasons the Environment variable is not being pushed from lambda output to the Container as launch override. Is there something that I am doing incorrectly ?
Thanks
Container overrides need to go into the Parameters
attributes of your Action in your state machine. Here is an example that will retrieve the "foo"
attribute from the input and set it as an environment variable:
{
"States":{
...,
"Manage ECS task":{
"Type":"Task",
"Resource":"arn:aws:states:::ecs:runTask.waitForTaskToken",
"Parameters":{
"LaunchType":"FARGATE",
"Cluster":"cluster-arn",
"TaskDefinition":"job-id",
"Overrides":{
"ContainerOverrides":[
{
"Name":"container-name",
"Environment":[
{
"Name":"FOO_FROM_INPUT",
"Value.$":"$.foo"
}
]
}
]
}
}
}
}
}
If your input supplies the entire value of the "ContainerOverrides"
configuration, then you can do something like this:
{
"States":{
...,
"Manage ECS task":{
"Type":"Task",
"Resource":"arn:aws:states:::ecs:runTask.waitForTaskToken",
"Parameters":{
"LaunchType":"FARGATE",
"Cluster":"cluster-arn",
"TaskDefinition":"job-id",
"Overrides":{
"ContainerOverrides.$": "$.containerOverrides"
}
}
}
}
}
See also Pass State Input as Parameters Using Paths in the Step Functions documentation.
Relevant questions
Write containerOverwrites from Lambda to Container
asked 5 months agoHow do I keep the time in sync in docker based lambda functions
Accepted Answerasked 3 months agoIs it possible to kill/stop a running lambda function?
asked 5 years agoTimeoutError The action failed because a job worker exceeded its timelimit
asked 3 years agohow to trigger a step function from a s3 object notification?
asked a month agoAt what point is an AWS SQS queue overkill as a Lambda function's source?
asked 2 months agosqs event triggers lambda directly, is there a way to delay that execution by 10-20 seconds?
Accepted Answerasked 2 years agoHow to handle failed lambda functions
asked 2 months agoLambda queries do not reflect the database state
asked 2 years agoReturn Value from Lambda function triggered by SQS to individual client
Accepted Answerasked 4 months ago