Short answer: put an AwsCredentials block in your workspace, then reference it in the aws-push work pool’s base_job_template via a block ref.
Assuming Prefect 3.x and the prefecthq/prefect Terraform provider:
- Create (or reference) an AWS Credentials block (block type slug: aws-credentials).
- In your prefect_work_pool resource (type = "aws-push"), set base_job_template so its aws_credentials field is a block reference to that block.
Example: create the block and use it in an aws-push pool
- Provider docs:
- Work pool:
https://registry.terraform.io/providers/PrefectHQ/prefect/latest/docs/resources/work_pool
- Block document:
https://registry.terraform.io/providers/PrefectHQ/prefect/latest/docs/resources/block_document
Terraform
resource "prefect_block_document" "aws_creds" {
name = "my-aws-creds"
block_type_slug = "aws-credentials"
# Don’t hardcode secrets; use TF variables or a secrets manager
data = jsonencode({
aws_access_key_id = var.aws_access_key_id
aws_secret_access_key = var.aws_secret_access_key
region_name = "us-east-1"
# Optional:
# aws_session_token = var.aws_session_token
# profile_name = "my-aws-profile"
})
}
resource "prefect_work_pool" "aws_push" {
name = "aws-push-pool"
type = "aws-push"
# The aws-push worker’s job variables support an aws_credentials ref
base_job_template = jsonencode({
region_name = "us-east-1"
cluster = "my-ecs-cluster"
launch_type = "FARGATE"
subnets = ["subnet-abc", "subnet-def"]
security_groups = ["sg-123456"]
assign_public_ip = true
# Reference the AWS Credentials block created above
aws_credentials = {
"$ref" = {
block_document_id = prefect_block_document.aws_creds.id
# Alternatively, if you prefer to reference by name:
# block_document_name = prefect_block_document.aws_creds.name
}
}
})
}
Notes
- The aws-push worker’s schema supports an aws_credentials field that accepts a block reference. Using block_document_id is the safest; name works if it’s unique in the workspace.
- Make sure the prefect-aws collection (which defines the AwsCredentials block type) is available in your Prefect environment; on Prefect Cloud it’s already registered.
- Avoid committing plaintext AWS secrets in Terraform; use variables, TF Cloud variables, or a secret manager.
If you already have an AWS Credentials block you want to reuse, let me know its name; I can show the minimal work_pool resource referencing it directly. Or, if your org relies on instance roles and doesn’t want static keys, you can create the block with only region_name and profile_name (or even omit the block and rely on the worker’s IAM role), though for push pools Prefect needs credentials server-side to call ECS.