This recipe will walk you through the process to create a Prefect Agent using the AWS CLI.
- This guide provides an example for creating a role which allows S3 read access, it is likely that your agent will require additional roles, creation of which is outside the scope of this guide.
- Create a Service Account in Prefect Cloud
- Edit the
prefect-agent-td.json
and fill in values for:WORK_QUEUE_ID
PREFECT_API_KEY
PREFECT_API_URL
- Optional: Create a role with S3 read permissions to attach to the agent:
aws iam create-role --role-name PrefectECSRole --assume-role-policy-document file://trust-policy.json
aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess --role-name PrefectECSRole
- Use AWS CLI to register your task definition
aws ecs register-task-definition --cli-input-json file://<full_path_to_task_definition_file>/prefect-agent-td.json
- Create a service from your task definition, taking care to fill in any network-configuration:
aws ecs create-service --service-name prefect-agent \ --task-definition prefect-agent:1 \ --desired-count 1 \ --launch-type FARGATE \ --platform-version LATEST \ --cluster default \ --network-configuration "awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321],assignPublicIp=ENABLED}" \ --tags key=key1,value=value1 key=key2,value=value2 key=key3,value=value3 \ --role