admin管理员组文章数量:1126345
Basically I'm building a integration that runs a ECR image on ECS via a AWS batch job definition. This piece of the code works atm, and we're now moving to running the job definitions via a AWS step function.
Here is a copy of my current state machine (with some edits for the privacy of the companies involved in this code)
{
"Comment": "A description of my state machine",
"StartAt": "xxxxxx Job",
"QueryLanguage": "JSONata",
"States": {
"blahblah Job": {
"Type": "Task",
"Resource": "arn:aws:states:::batch:submitJob.sync",
"Arguments": {
"JobName": "blahJob",
"JobDefinition": "job-def-arn:69",
"JobQueue": "job-queue"
},
"Next": "bleg Job",
"Assign": {
"apiCall": "$states.input.apiCall",
"wid": "$states.input.wid"
}
},
"bleg Job": {
"Type": "Task",
"Resource": "arn:aws:states:::batch:submitJob.sync",
"Arguments": {
"JobDefinition": "job-arn:69",
"JobQueue": "job-queue",
"JobName": "blegJob"
},
"End": true,
"Assign": {
"apiCall": "$states.input.apiCall",
"person": "$states.input.person",
"endpoint": "$states.input.endpoint"
}
}
}
}
I've been trying a couple of different methods. My ECR images are an alpine linux image running a nodejs code. The ECR repo and the Batch job are all created via Terraform. The above assign block did not work correctly.
Here's a copy of the terraform job definition that is being run via the step functions. You can see I've tried setting the enviroment variables via the terraform as well, but that's not been working for me either.
Let me know if there's any more info I can shed on my setup, or if there are any techniques or tricks I should try.
resource "aws_batch_job_definition" "managed" {
for_each = var.manage_job_definitions ? var.job_definitions : {}
name = "${var.app_name}-${var.environment}-${each.key}"
type = "container"
platform_capabilities = [
"FARGATE",
]
container_properties = <<CONTAINER_PROPERTIES
{
"fargatePlatformConfiguration": {
"platformVersion": "LATEST"
},
"executionRoleArn": "${aws_iam_role.ecs_task_execution_role.arn}",
"jobRoleArn": "${local.ecs_job_role}",
"mountPoints": ${jsonencode(var.mount_points)},
"volumes": ${jsonencode(var.volumes)},
"containers": [
{
"name": "xxxxx",
"image": "${xxxxx}",
"environment": [
{
"name": "apiCall",
"value": "{% $states.input.apiCall $}"
},
{
"name": "wid",
"value": "{% $states.input.xxx $}"
}
],
"environment": ${jsonencode(concat(localmon_env_vars, each.value.environment_variables))},
"essential": true,
"resourceRequirements": [
{"type": "VCPU", "value": "0.25"},
{"type": "MEMORY", "value": "512"}
]
},
{
"name": "xxxxxImage",
"image": "${var.xxxx_image}",
"environment": [
{
"name": "apiCall",
"value": "{% $states.input.apiCall $}"
},
{
"name": "wid",
"value": "{% $states.input.wid $}"
}
],
"essential": true,
"resourceRequirements": [
{"type": "VCPU", "value": "0.25"},
{"type": "MEMORY", "value": "512"}
]
},
{
"name": "dataImage",
"image": "${var.node_server_image}",
"environment": ${jsonencode(concat(localmon_env_vars, each.value.environment_variables))},
"essential": true,
"resourceRequirements": [
{"type": "VCPU", "value": "0.25"},
{"type": "MEMORY", "value": "512"}
]
}
]
}
CONTAINER_PROPERTIES
}
Basically I'm building a integration that runs a ECR image on ECS via a AWS batch job definition. This piece of the code works atm, and we're now moving to running the job definitions via a AWS step function.
Here is a copy of my current state machine (with some edits for the privacy of the companies involved in this code)
{
"Comment": "A description of my state machine",
"StartAt": "xxxxxx Job",
"QueryLanguage": "JSONata",
"States": {
"blahblah Job": {
"Type": "Task",
"Resource": "arn:aws:states:::batch:submitJob.sync",
"Arguments": {
"JobName": "blahJob",
"JobDefinition": "job-def-arn:69",
"JobQueue": "job-queue"
},
"Next": "bleg Job",
"Assign": {
"apiCall": "$states.input.apiCall",
"wid": "$states.input.wid"
}
},
"bleg Job": {
"Type": "Task",
"Resource": "arn:aws:states:::batch:submitJob.sync",
"Arguments": {
"JobDefinition": "job-arn:69",
"JobQueue": "job-queue",
"JobName": "blegJob"
},
"End": true,
"Assign": {
"apiCall": "$states.input.apiCall",
"person": "$states.input.person",
"endpoint": "$states.input.endpoint"
}
}
}
}
I've been trying a couple of different methods. My ECR images are an alpine linux image running a nodejs code. The ECR repo and the Batch job are all created via Terraform. The above assign block did not work correctly.
Here's a copy of the terraform job definition that is being run via the step functions. You can see I've tried setting the enviroment variables via the terraform as well, but that's not been working for me either.
Let me know if there's any more info I can shed on my setup, or if there are any techniques or tricks I should try.
resource "aws_batch_job_definition" "managed" {
for_each = var.manage_job_definitions ? var.job_definitions : {}
name = "${var.app_name}-${var.environment}-${each.key}"
type = "container"
platform_capabilities = [
"FARGATE",
]
container_properties = <<CONTAINER_PROPERTIES
{
"fargatePlatformConfiguration": {
"platformVersion": "LATEST"
},
"executionRoleArn": "${aws_iam_role.ecs_task_execution_role.arn}",
"jobRoleArn": "${local.ecs_job_role}",
"mountPoints": ${jsonencode(var.mount_points)},
"volumes": ${jsonencode(var.volumes)},
"containers": [
{
"name": "xxxxx",
"image": "${xxxxx}",
"environment": [
{
"name": "apiCall",
"value": "{% $states.input.apiCall $}"
},
{
"name": "wid",
"value": "{% $states.input.xxx $}"
}
],
"environment": ${jsonencode(concat(local.common_env_vars, each.value.environment_variables))},
"essential": true,
"resourceRequirements": [
{"type": "VCPU", "value": "0.25"},
{"type": "MEMORY", "value": "512"}
]
},
{
"name": "xxxxxImage",
"image": "${var.xxxx_image}",
"environment": [
{
"name": "apiCall",
"value": "{% $states.input.apiCall $}"
},
{
"name": "wid",
"value": "{% $states.input.wid $}"
}
],
"essential": true,
"resourceRequirements": [
{"type": "VCPU", "value": "0.25"},
{"type": "MEMORY", "value": "512"}
]
},
{
"name": "dataImage",
"image": "${var.node_server_image}",
"environment": ${jsonencode(concat(local.common_env_vars, each.value.environment_variables))},
"essential": true,
"resourceRequirements": [
{"type": "VCPU", "value": "0.25"},
{"type": "MEMORY", "value": "512"}
]
}
]
}
CONTAINER_PROPERTIES
}
Share
Improve this question
asked Jan 8 at 22:50
gatorpatchgatorpatch
194 bronze badges
1 Answer
Reset to default 0I ended up figuring it out thanks to some people over on reddit. You just need to add
"ContainerOverrides": {
"Environment": [
{
"Name": "var1",
"Value": "{% $states.input.value1 %}"
},
{
"Name": "var2",
"Value": "{% $states.input.value2 %}"
}
]
}
to whichever container you are trying to get the variables into on the State Machine/Step Function definition, under the Arguments field.
本文标签:
版权声明:本文标题:node.js - Having trouble passing environmental variables into a batch job triggered by a step function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736683800a1947559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论