ale
07/07/2021, 5:33 PMKevin Kho
ale
07/07/2021, 7:42 PMKevin Kho
ale
07/07/2021, 7:58 PMKevin Kho
ale
07/07/2021, 7:59 PMale
07/08/2021, 2:48 PMcontainerDefinitions_environment
so that we can pass environment variables to the task that runs the flow.
Is this still possible with the ECS Agent?Kevin Kho
ale
07/08/2021, 2:52 PMale
07/08/2021, 2:52 PMKevin Kho
env
of ECSRun will pass throughKevin Kho
register_task_definition
.ale
07/08/2021, 2:56 PMcontainerDefinitions_environment
I can define env var at the agent level and then they are passed to the flow…ale
07/08/2021, 2:57 PMale
07/08/2021, 3:01 PMrAgentFargateTaskDefinition:
Type: 'AWS::ECS::TaskDefinition'
Metadata:
cfn-lint:
config:
ignore_checks:
- E1029
DependsOn:
- rFlowTaskRolePolicy
- rAgentTaskRolePolicy
Properties:
TaskRoleArn: !Ref 'rAgentTaskRole'
ExecutionRoleArn: !GetAtt 'rAgentExecutionRole.Arn'
Family: !Sub '${pEnvironment}-prefect-fargate-agent'
ContainerDefinitions:
- Name: 'agent'
Essential: true
Command: ['prefect', 'agent', 'start', 'fargate', 'enable_task_revisions=true']
Image: !Sub
- 'prefecthq/prefect:${version}'
- version: !If [ cIsPrefectServerVersionLatest, 'all_extras', !Sub 'all_extras-${pPrefectServerVersion}' ]
MemoryReservation: 128
Environment:
- Name: PREFECT__CLOUD__API
Value: !Sub '<masked value>'
- Name: PREFECT__BACKEND
Value: 'server'
- Name: PREFECT__CLOUD__AGENT__LABELS
Value: '["heavy"]'
- Name: REGION_NAME
Value: !Ref AWS::Region
- Name: executionRoleArn
Value: !GetAtt 'rFlowsExecutionRole.Arn'
- Name: taskRoleArn
Value: !GetAtt 'rFlowsTaskRole.Arn'
- Name: networkMode
Value: 'awsvpc'
- Name: cluster
Value: !Ref pEcsCluster
- Name: networkConfiguration
Value: !Sub
- '{"awsvpcConfiguration": {"assignPublicIp": "DISABLED", "subnets": ["${subnets}"], "securityGroups": ["${pDWHClientSecurityGroup}"]}}'
- subnets: !Join ['","', !Ref pFargateSubnetIds]
- Name: cpu
Value: '4096'
- Name: memory
Value: '8192'
- Name: containerDefinitions_environment
Value: !Sub
- '[{
"name": "AWS_DEFAULT_REGION",
"value": "${AWS::Region}"
}, {
"name": "INTERNAL_SERVICES_CONNECTION_DATA_SECRET_ARN",
"value": "${rPrefectAgentInternalServicesConnectionDataSecret}"
}, {
"name": "DWH_JSON_CONNECTION_DATA_SECRET_ARN",
"value": "${rPrefectAgentDWHConnectionDataSecret}"
}, {
"name": "PLATFORM_DB_JSON_CONNECTION_DATA_SECRET_ARN",
"value": "${rPrefectAgentPlatformDBConnectionDataSecret}"
}, {
"name": "ENVIRONMENT",
"value": "${pEnvironment}"
}, {
"name": "DWH_QUERY_ROLE_ARN",
"value": "${pSafelakeDWHClusterRoleArn}"
}, {
"name": "EXTERNAL_SERVICES_SECRETS",
"value": "${rPrefectAgentExternalServicesSecret}"
}, {
"name": "DWH_PLATFORM_POSTGRES_USER_SECRET_ARN",
"value": "${pDWHPostgreSQLVersion11UserSecretArn}"
}, {
"name": "SAFELAKE_BUCKET_INGESTION_NAME",
"value": "${SafelakeBucketIngestionName}"
}, {
"name": "PREFECT__CONTEXT__SECRETS__SLACK_WEBHOOK_URL",
"value": "${pSlackWebhook}"
}, {
"name": "ROLLBAR_ENABLED",
"value": "true"
}, {
"name": "SLACK_ENABLED",
"value": "true"
}, {
"name": "PREFECT__SERVER__UI__ENDPOINT",
"value": "<masked_value>"
}
]'
- SafelakeBucketIngestionName: !Select [1, !Split [':::', !Ref pDatalakeBucketArn]]
- Name: containerDefinitions_logConfiguration
Value: !Sub '{ "logDriver": "awslogs", "options": { "awslogs-group": "${rFlowsLogsGroup}", "awslogs-region": "${AWS::Region}", "awslogs-stream-prefix": "prefect-flow"}}'
LogConfiguration:
LogDriver: 'awslogs'
Options:
awslogs-group: !Ref 'rAppLogsGroup'
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: 'prefect-agent'
Tags:
- Key: 'Name'
Value: !Sub '${pEnvironment}-prefect-fargate-agent'
- Key: 'ApplicationVersion'
Value: !Ref 'pApplicationVersion'
Kevin Kho
--env
CLI flag on the agent are also passed through. Is that what you need?ale
07/08/2021, 3:02 PMEnvironment
instead of the --env
CLI flag?Kevin Kho
Kevin Kho
ale
07/08/2021, 3:08 PMEnvironment
parameter.
Otherwise we’ll have to provide all values in the command
parameter where we start the agent (passing values as you said using --env
CLI flag)ale
07/09/2021, 4:27 PM--env
CLI flag to pass my env vars.
I just need to understand if using the Environment
in the task definition of the agent would work as well simple smileMariia Kerimova
07/09/2021, 10:10 PM--env
CLI flag on agent or using ECSAgent(env_vars=..)
or ECSRun(env=..)
) will not pass the env var to the flow. I'll ask the team if we can have implicit env vars discoveryale
07/10/2021, 7:52 AMale
07/12/2021, 7:40 PMMariia Kerimova
07/12/2021, 7:43 PM--env
CLI param in the Command parameter in the ECS task definition, the environment variables will be passed to the flow 🙂Mariia Kerimova
07/12/2021, 7:51 PM--env
or ECSRun(env=..)
or ECSAgent(env_var)
, the variables will not be passed to the flow runs, but if you'll specify variables using --env
it should work 👍 I hope it makes sense, if not, let me know and I'll try to give you an example.ale
07/12/2021, 7:56 PM--env
the values defined in the Environment would be super appreciated!Mariia Kerimova
07/12/2021, 8:48 PM--env
will look like this in the console:Mariia Kerimova
07/12/2021, 8:50 PMProperties:
TaskRoleArn: !Ref 'rAgentTaskRole'
ExecutionRoleArn: !GetAtt 'rAgentExecutionRole.Arn'
Family: !Sub '${pEnvironment}-prefect-fargate-agent'
ContainerDefinitions:
- Name: 'agent'
Essential: true
Command: ['prefect', 'agent', 'ecs', 'start', 'TEST_ECS_ENV=value_of_env_var']
Mariia Kerimova
07/12/2021, 8:53 PMMariia Kerimova
07/12/2021, 8:54 PMfrom prefect.storage import Docker
from prefect.executors import LocalExecutor
from prefect.run_configs import ECSRun
from prefect import task, Flow
import prefect
import os
STORAGE = Docker(
registry_url="mariiaprefect",
image_name="envvars-testflow",
)
RUN_CONFIG = ECSRun(run_task_kwargs={"cluster": "default-cluster"}, labels=["masha", "envtoken"])
EXECUTOR = LocalExecutor()
@task
def print_me():
logger = prefect.context.get("logger")
env_value = os.environ['TEST_ECS_ENV']
<http://logger.info|logger.info>(f"Got the env var {env_value}")
with Flow(
"Ale", storage=STORAGE, run_config=RUN_CONFIG
) as flow:
print_me()
ale
07/12/2021, 9:06 PMTEST_ECS_ENV=${pEnvironment}
where pEnvironment is a parameter defined in teh CFN template.
Does this make sense?Mariia Kerimova
07/12/2021, 9:08 PMale
07/12/2021, 9:16 PM