Write containerOverwrites from Lambda to Container

0

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

1개 답변
0

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.

AWS
전문가
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠