Closed qzysw123456 closed 1 year ago
Additionally, it would be useful to see how to read event metadata (e.g. bucket/key of the file uploaded; if possible) from inside the container. I found 0 resources about this online, maybe there is some ENV inside container that isn't documenented?
@ajdinm ,
While creating rule target, InputTransformer attibute can be used to pass meatdata to Target.
For ECS task as a target, AWS console do not provide option to provide InputTransformer attribute. We can specify it while creating resource via CloudFormation/Terraform or using AWS CLI.
Please find following AWS CLI command to ECS task target to existing rule and provide metadata.
aws events put-targets --rule "name of rule" --targets '{
"Id": "9",
"Arn": "arn of ECS cluster",
"RoleArn": "arn of role to invoke ECS task",
"EcsParameters": {
"TaskDefinitionArn": "arn of task definition",
"TaskCount": 1,
"LaunchType": "FARGATE",
"NetworkConfiguration": {
"awsvpcConfiguration": {
"Subnets": [
"id of subnet"
],
"AssignPublicIp": "DISABLED"
}
},
"Group": "demo"
},
"InputTransformer": {
"InputPathsMap": {
"s3-bucket": "$.detail.requestParameters.bucketName",
"s3-key": "$.detail.requestParameters.key"
},
"InputTemplate": "{
\"containerOverrides\": [
{
\"name\": \"name of container in task def\",
\"environment\": [
{
\"name\": \"s3-bucket\",
\"value\": \"<s3-bucket>\"
},
{
\"name\": \"s3-key\",
\"value\": \"<s3-key>\"
}
]
}
]
}"
}
}'
Metadata will be passed to container as environment variable. I am using dotnet core based container hence I am accessing those variables as follow. Console.WriteLine($"bucket name: {Environment.GetEnvironmentVariable("s3-bucket")}"); Console.WriteLine($"file name: {Environment.GetEnvironmentVariable("s3-key")}");
This is helpful, thank you @iamdakshay .
Closing this issue or pull request in advance of archiving this repo. For more information about the decision to archive this repo (and others in the 'awsdocs' org), see the announcement on the AWS News Blog.
https://github.com/awsdocs/amazon-cloudwatch-events-user-guide/blob/master/doc_source/CloudWatch-Events-tutorial-ECS.md
It mentioned everything but Cloudtrail. From my experience it doesn't work otherwise you correctly setting up cloud trail and log object level API calls to a logGroup