项目作者: rluisr

项目描述 :
Monitoring the ECS task event
高级语言: Go
项目地址: git://github.com/rluisr/ecssc.git
创建时间: 2020-12-12T16:17:43Z
项目社区:https://github.com/rluisr/ecssc

开源协议:Do What The F*ck You Want To Public License

下载


ecssc

ecssc(ECS State Check) is a Lambda function for notification to Slack if the ECS task event is changed.

image

Download

See GitHub Container Registry

Installation

ecssc is a Lambda function of EventBridge event target.

image

Copy the container image to your ECR repository.
The Lambda does not support third-party container registry.

This is an example for setting up EventBridge and Lambda with Terraform.

EventBridge:

  1. resource "aws_cloudwatch_event_bus" "ecs-state-check" {
  2. name = "ecs-state-check"
  3. }
  4. resource "aws_cloudwatch_event_rule" "ecs-state-check" {
  5. name = "ecs-state-check"
  6. event_pattern = <<EOF
  7. {
  8. "source": [
  9. "aws.ecs"
  10. ],
  11. "detail-type": [
  12. "ECS Task State Change",
  13. "ECS Container Instance State Change"
  14. ]
  15. }
  16. EOF
  17. }

Lambda:

  1. # ECR
  2. resource "aws_ecr_repository" "foo" {
  3. name = "ecs-state-check"
  4. image_tag_mutability = "MUTABLE"
  5. image_scanning_configuration {
  6. scan_on_push = false
  7. }
  8. }
  9. # CloudWatch Log Group
  10. resource "aws_cloudwatch_log_group" "ecs-state-check" {
  11. name = "/aws/lambda/ecs-state-check"
  12. retention_in_days = 14
  13. }
  14. # IAM role for Lambda
  15. module "ecs-state-check_lambda_execution_role" {
  16. source = "baikonur-oss/iam-nofile/aws"
  17. version = "v2.0.0"
  18. type = "lambda"
  19. name = "ecs-state-check"
  20. policy_json = <<EOF
  21. {
  22. "Version": "2012-10-17",
  23. "Statement": [
  24. {
  25. "Effect": "Allow",
  26. "Action": [
  27. "logs:CreateLogStream",
  28. "logs:PutLogEvents"
  29. ],
  30. "Resource": "*"
  31. },
  32. {
  33. "Effect": "Allow",
  34. "Action": [
  35. "ssm:GetParametersByPath"
  36. ],
  37. "Resource": "arn:aws:ssm:${data.aws_region.region.name}:${data.aws_caller_identity.caller.account_id}:parameter${var.parameter_store_path}"
  38. },
  39. {
  40. "Effect": "Allow",
  41. "Action": [
  42. "ecs:Describe*"
  43. ],
  44. "Resource": "*"
  45. }
  46. ]
  47. }
  48. EOF
  49. }
  50. # Lambda
  51. resource "aws_lambda_function" "ecs-state-check" {
  52. function_name = "ecs-state-check"
  53. image_uri = "to your ecr image uri"
  54. package_type = "Image"
  55. role = module.ecs-state-check_lambda_execution_role.arn
  56. }
  57. # Trigger
  58. resource "aws_lambda_permission" "ecs-state-check" {
  59. action = "lambda:InvokeFunction"
  60. function_name = aws_lambda_function.ecs-state-check.function_name
  61. principal = "events.amazonaws.com"
  62. source_arn = "arn:aws:events:ap-northeast-1:111111111111:rule/ecs-state-check"
  63. }

Environment Variables

Name Description Required
ECSSC_DEBUG Show debug message. default: false no
ECSSC_IGNORE_CONTAINER_NAMES Skip container names. Support array like app1,app2 no
ECSSC_SLACK_CHANNEL_NAME Slack channel name like ‘#test’ yes
ECSSC_SLACK_WEBHOOK_URL Slack incoming webhook URL yes
ECSSC_SLACK_USER_NAME Slack Username default ‘ecs-state-check’ no
ECSSC_SLACK_ICON_URL Slack icon URL no
ECSSC_SLACK_ICON_EMOJI Slack icon emoji. default ‘:japanese_goblin: no