Abhishek
09/20/2021, 11:06 AMprefect agent ecs start --key $KEY --task-role-arn $TASK_ARN --log-level INFO --label s3_sync --name farget-dev --execution-role-arn $EXEC_ROLE_ARN
and its giving me an error:
ValueError: Failed to infer default networkConfiguration, please explicitly configure using `--run-task-kwargs`
I am created a ecs cluster (using default). I used following command to use create cluster:
aws ecs create-cluster
which creates a default cluster.
Can anyone point out if i am missing anything?Anna Geller (old account)
09/20/2021, 11:26 AMnetworkConfiguration
. You could extract the subnet IDs this way:
export AWS_REGION=set_your_region
SUBNETS=$(aws ec2 describe-subnets --region $AWS_REGION)
export SUBNET1=$(echo $SUBNETS | jq -r '.Subnets | .[0].SubnetId')
export SUBNET2=$(echo $SUBNETS | jq -r '.Subnets | .[1].SubnetId')
export SUBNET3=$(echo $SUBNETS | jq -r '.Subnets | .[2].SubnetId')
And then you can set it as environment variable:
export networkConfiguration="{'awsvpcConfiguration': {'assignPublicIp': 'ENABLED', 'subnets': ['$SUBNET1', '$SUBNET2', '$SUBNET3'], 'securityGroups': []}}"
Anna Geller (old account)
09/20/2021, 11:28 AMAbhishek
09/20/2021, 11:30 AM--run-task-kwargs task_def.yaml
let me try with --network-configuration
Abhishek
09/20/2021, 12:03 PMAnna Geller (old account)
09/20/2021, 12:07 PMAbhishek
09/20/2021, 12:16 PMAbhishek
09/20/2021, 12:16 PMKevin Kho
run-task-kwargs
should work. Does yours look like this ?Kevin Kho
Anna Geller (old account)
09/20/2021, 1:59 PMKevin Kho
Kevin Kho
Anna Geller (old account)
09/20/2021, 2:03 PMAnna Geller (old account)
09/20/2021, 2:43 PMimport prefect
from prefect.storage import S3
from prefect.run_configs import ECSRun
from prefect import task, Flow
@task
def say_hi():
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("Hi from Prefect %s", prefect.__version__)
with Flow(
"hello-from-ecs",
storage=S3(bucket="prefect-datasets", key="flows/example_ecs_flow.py", stored_as_script=True),
run_config=ECSRun(
labels=["prod"],
task_role_arn="arn:aws:iam::12345678:role/prefectTaskRole",
run_task_kwargs=dict(cluster="prefectEcsCluster", launchType="FARGATE",),
),
) as flow:
say_hi()
if __name__ == "__main__":
flow.register("01_Basics")
Abhishek
09/20/2021, 2:44 PMAbhishek
09/20/2021, 6:08 PMKevin Kho
Abhishek
09/20/2021, 6:12 PMKevin Kho
aws ec2 describe-subnets --region $AWS_REGION
?Abhishek
09/20/2021, 6:16 PMaws ec2 describe-subnets --region $AWS_REGION --filters Name=vpc-id,Values=vpc-0xxxxx
Abhishek
09/20/2021, 6:17 PMKevin Kho
Kevin Kho
Abhishek
09/20/2021, 6:23 PMKevin Kho
create service
Anna Geller (old account)
09/20/2021, 10:27 PMAbhishek
09/21/2021, 3:06 PMKevin Kho
Kevin Kho
Abhishek
09/21/2021, 3:12 PMKevin Kho
Abhishek
09/21/2021, 3:31 PMKevin Kho
Abhishek
09/21/2021, 4:11 PMAbhishek
09/21/2021, 4:13 PMKevin Kho
Kevin Kho
Abhishek
09/21/2021, 4:17 PMAbhishek
09/21/2021, 4:18 PMKevin Kho
Abhishek
09/21/2021, 4:22 PMKevin Kho
Abhishek
09/21/2021, 4:24 PMAbhishek
09/21/2021, 4:25 PMKevin Kho
Kevin Kho
Abhishek
09/21/2021, 4:27 PMKevin Kho
Abhishek
09/21/2021, 4:29 PMKevin Kho
Abhishek
09/21/2021, 4:30 PMservice pm-dev-ecs-prefect was unable to place a task because no container instance met all of its requirements. Reason: No Container Instances were found in your cluster. For more information, see the Troubleshooting section.
Abhishek
09/21/2021, 4:36 PMnetwork_configuration {
subnets = var.subnet_ids
assign_public_ip = true
security_groups = [aws_security_group.pm-ecs-prefect.id]
}
subnet_ids = [data.terraform_remote_state.pm-dev-vpc.outputs.pm-dev-public-subnet-a,
data.terraform_remote_state.pm-dev-vpc.outputs.pm-dev-public-subnet-b,
data.terraform_remote_state.pm-dev-vpc.outputs.pm-dev-public-subnet-c]
Abhishek
09/21/2021, 4:36 PMvar.subnet.id
does that.Anna Geller (old account)
09/21/2021, 11:46 PMAnna Geller (old account)
09/22/2021, 12:21 PMcommand: [
"prefect",
"agent",
"ecs",
"start",
"--run-task-kwargs",
"<s3://xyz/run_task_kwargs.yaml>"
],
2. Custom VPC required custom YAML creation and upload to S3 for tasks to pick up - used terraform
for that - but was painful to get correct initially
3. Task definition needs AWS_DEFAULT_REGION
env var as well
4. "'dev','etl'"
works without the square brackets for PREFECT__CLOUD__AGENT__LABELS
env var
5. Creating subnets on the fly and creating associations for route tables via terraform
took some work
6. Few other networking fixes relevant to our environmentJonathan Buys
10/26/2021, 4:29 PMrun_task_kwargs.yaml
file?Kevin Kho
Jonathan Buys
10/26/2021, 4:37 PMJonathan Buys
10/26/2021, 5:19 PMrun_task_kwargs.yaml
file:
executionRoleArn: arn:aws:iam::XXX:role/ecsTaskExecutionRole
containerDefinitions:
- memory: 1024
memoryReservation: 512
volumesFrom: []
image: prefecthq/prefect
essential: true
name: flow
placementConstraints: []
memory: '4096'
taskRoleArn: arn:aws:iam::XXX:role/prefect-ecs-task-role
requiresCompatibilities:
- FARGATE
networkMode: awsvpc
cpu: '1024'
network_configuration:
subnets: [subnet-XXX]
assign_public_ip: true
security_groups: [sg-XXX]
But I'm still getting the Failed to infer default networkConfiguration
error in ECS.Kevin Kho
network_configuration
or networkConfiguration
? or did you try both?Jonathan Buys
10/26/2021, 5:33 PMJonathan Buys
10/26/2021, 5:37 PMKevin Kho
Jonathan Buys
10/26/2021, 5:51 PMno such option: --key
when running my command, defined as:
"command": [
"prefect",
"agent",
"ecs",
"start",
"--key",
"ZZZZZZ",
"--run-task-kwargs",
"<s3://ts-codedeploy/run_task_kwargs.yaml>"
In my task definition. Is the --key
option a recent addition?Jonathan Buys
10/26/2021, 5:52 PMKevin Kho
Jonathan Buys
10/26/2021, 6:04 PMKevin Kho
Jonathan Buys
10/27/2021, 3:20 PMnetworkConfiguration:
awsvpcConfiguration:
subnets: [subnet-XXXX]
assignPublicIp: "ENABLED"
securityGroups: [sg-XXXXXXXXXXX]
John Shearer
12/10/2021, 10:17 AMJohn Shearer
12/10/2021, 10:19 AMAnna Geller
Kevin Kho
Abhishek
12/15/2021, 5:50 PM