個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證製作者的介紹僅有上面的一句話。 更多詳情請閱讀儲存庫 README。 儲存庫 README ↗
正在載入完整 README。
檢視完整 README ↗Terraform module for provisioning an SQS queue paired with an ECS service to run containerized queue consumers.
Running containerized SQS consumers on AWS requires orchestrating many services:
This module solves these problems by:
consumer_on_demand_base_capacity)The module is similar to terraform-aws-sqs-pod, but runs consumers from Docker images instead of deploying directly on EC2 instances.
module "sqs_consumer" {
source = "registry.infrahouse.com/infrahouse/sqs-ecs/aws"
version = "3.2.0"
service_name = "my-consumer"
consumer_subnet_ids = var.private_subnet_ids
consumer_docker_image = "my-org/my-consumer:latest"
alert_notification_email = "[email protected]"
consumer_on_demand_base_capacity = 0 # Use spot instances
}
When the consumer image lives in ECR, the repository's lifecycle policy can prune an image that is still actively deployed. If the consumer is not redeployed for a while and newer images are pushed, the deployed image may be deleted, which breaks recovery (a new EC2 host cannot pull it) and leaves stale, vulnerable images around.
Set enable_ecr_image_tagging = true to deploy a small Lambda alongside the
consumer service. Each time the service reaches steady state, the Lambda tags
the actively deployed image with deployed-at-<timestamp>. Pair this with the
matching retention rule in
infrahouse/terraform-aws-ecr,
which preserves deployed-at-* tagged images.
module "sqs_consumer" {
source = "registry.infrahouse.com/infrahouse/sqs-ecs/aws"
version = "3.2.0"
service_name = "my-consumer"
consumer_subnet_ids = var.private_subnet_ids
consumer_docker_image = "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-consumer:latest"
alert_notification_email = "[email protected]"
enable_ecr_image_tagging = true
}
consumer_docker_image must be an ECR image URI when this is enabled. Images
pulled from Docker Hub or public ECR are silently skipped.
Without a dead-letter queue, a message that every consumer fails on returns to the queue after each visibility timeout and is received again until it expires, 4 days by default.
Set enable_dead_letter_queue = true to create one, named after the queue with
-dlq (<name>-dlq.fifo for a FIFO queue). A message received
dead_letter_queue_max_receive_count times (5 by default) without being deleted
moves there. The dead-letter queue keeps messages 14 days, SQS's maximum, but a
standard queue's message keeps the time it was first sent: it expires 14 days
after that, so at least 10 days after the move, since the queue keeps messages
4. A FIFO queue's message gets 14 days from the move. An alarm emails
alert_notification_email when the dead-letter queue holds any message.
module "sqs_consumer" {
source = "registry.infrahouse.com/infrahouse/sqs-ecs/aws"
version = "3.2.0"
service_name = "my-consumer"
consumer_subnet_ids = var.private_subnet_ids
consumer_docker_image = "my-org/my-consumer:latest"
alert_notification_email = "[email protected]"
enable_dead_letter_queue = true
}
It is off by default, so an upgrade changes nothing for a module that doesn't
set it. If you already set a redrive policy on queue_url yourself, keep the
option off: the module's redrive policy would replace yours. Turning it off
again removes the queue's redrive policy and deletes the dead-letter queue, with
any messages still in it.
Full documentation is available at infrahouse.github.io/terraform-aws-sqs-ecs.
| Name | Version |
|---|---|
| aws | >= 6.0, < 7 |
| Name | Version |
|---|---|
| aws | 6.50.0 |
| Name | Source | Version |
|---|---|---|
| asg | ./modules/asg | n/a |
| ecs | ./modules/ecs | n/a |
| scaling | ./modules/scaling | n/a |
| Name | Type |
|---|---|
| aws_cloudwatch_dashboard.this | resource |
| aws_cloudwatch_metric_alarm.dead_letter_queue_depth | resource |
| aws_cloudwatch_metric_alarm.sqs_age_alarm | resource |
| aws_sns_topic.sqs_alarms | resource |
| aws_sns_topic_subscription.email_subscription | resource |
| aws_sqs_queue.dead_letter | resource |
| aws_sqs_queue.queue | resource |
| aws_sqs_queue_redrive_policy.queue | resource |
| aws_caller_identity.current | data source |
| aws_ec2_instance_type.consumer | data source |
| aws_region.current |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| alert_notification_email | Email address to receive alert notifications. | string | n/a | yes |
| cloudwatch_agent_image | CloudWatch agent container image. | string | "amazon/cloudwatch-agent:latest" | no |
| consumer_ami_id | AMI id for EC2 instances. By default, latest ECS optimized image. | string | null | no |
| consumer_asg_max_size | Minimum number of instances in ASG. By default, calculated from var.consumer_task_max_count. | number | null | no |
| consumer_asg_min_size | Minimum number of instances in ASG. By default, the number of subnets. | number | null | no |
| consumer_docker_image | A container image that will run the consumer application. | string | n/a | yes |
| consumer_extra_files |
| Name | Description |
|---|---|
| dead_letter_queue_arn | Dead-letter queue ARN, or null when enable_dead_letter_queue is false |
| dead_letter_queue_name | Dead-letter queue name, or null when enable_dead_letter_queue is false |
| dead_letter_queue_url | Dead-letter queue URL, or null when enable_dead_letter_queue is false |
| queue_arn | SQS Queue ARN |
| queue_name | SQS Queue name |
| queue_url | SQS Queue URL |
| service_arn | Consumer ECS Service ARN |
| service_name | Consumer ECS Service name |
| task_definition_arn | Consumer ECS task definition ARN |
| task_execution_role_arn |
See CONTRIBUTING.md for development setup and guidelines.
| data source |
| aws_subnet.selected | data source |
| Additional files to create on a host EC2 instance. |
| list( object( { content = string path = string permissions = string } ) ) |
[] |
| no |
| consumer_extra_policies | A map of additional policy ARNs to attach to the consumer instance role. | map(string) | {} | no |
| consumer_instance_type | Consumer EC2 Instance type | string | "t3a.small" | no |
| consumer_keypair_name | SSH key pair name that will be added to the consumer instance.By default, create and use a new SSH keypair. | string | null | no |
| consumer_on_demand_base_capacity | If specified, the ASG will request spot instances and this will be the minimal number of on-demand instances. | number | null | no |
| consumer_root_volume_size | Root volume size in consumer EC2 instance in Gigabytes | number | 30 | no |
| consumer_subnet_ids | List of subnet ids where the consumer instances will be created. | list(string) | n/a | yes |
| consumer_target_backlog_size | Target number of messages in the SQS backlog per task in ECS service. | number | 100 | no |
| consumer_target_cpu_load | Target CPU load for autoscaling. | number | 60 | no |
| consumer_task_commands | If specified, use this list of strings as a docker command. | list(string) | null | no |
| consumer_task_environment_variables | Environment variables passed down to a task. | list( object( { name : string value : string } ) ) | [] | no |
| consumer_task_execution_extra_policies | A map of extra policies attached to the task execution role. The key is an arbitrary string, the value is the policy ARN. | map(string) | {} | no |
| consumer_task_healthcheck_command | A shell command that a container runs to check if it's healthy. Exit code 0 means healthy, non-zero - unhealthy. | string | "exit 0" | no |
| consumer_task_max_count | Maximum number of ECS tasks. By default, calculated from consumer_asg_max_size. | number | null | no |
| consumer_task_min_count | Minimal number of ECS tasks. By default, calculated from var.consumer_asg_min_size. | number | null | no |
| consumer_task_quota_cpu | Number of CPU units that a container is going to use. One vCPU is equal to 1024 CPU units. | number | 200 | no |
| consumer_task_quota_memory | Hard memory limit in megabytes for the consumer container. | number | 128 | no |
| consumer_task_quota_memory_reservation | Soft memory limit in megabytes for the consumer container. ECS uses thisvalue for task placement when set, while the container can use memory upto consumer_task_quota_memory. | number | null | no |
| consumer_task_role_extra_policies | A map of extra policies attached to the task role. The key is an arbitrary string, the value is the policy ARN. | map(string) | {} | no |
| consumer_task_secrets | Secrets to pass to a container. A name will be the environment variable. valueFrom is a secret ARN. | list( object( { name : string valueFrom : string } ) ) | [] | no |
| consumer_task_volumes_efs | Map name->{file_system_id, container_path} of EFS volumes defined in task and available for containers to mount. | map( object( { file_system_id : string container_path : string } ) ) | {} | no |
| consumer_task_volumes_local | Map name->{host_path, container_path} of local volumes defined in task and available for containers to mount. | map( object( { host_path : string container_path : string } ) ) | {} | no |
| dead_letter_queue_max_receive_count | How many times consumers may receive a message without deleting it before SQS moves it tothe dead-letter queue. Only used when enable_dead_letter_queue is true. | number | 5 | no |
| deployed_image_tag_prefix | Prefix for the tag applied to ECR images after a successfuldeployment. The full tag is <prefix>YYYY-MM-DDTHH-MM-SSZ.Only used when enable_ecr_image_tagging is true. | string | "deployed-at-" | no |
| ecr_image_tagger_log_level | Log level for the ECR image tagger Lambda function.Set to "DEBUG" to log full EventBridge event payloads fortroubleshooting. Only used when enable_ecr_image_tagging is true. | string | "INFO" | no |
| enable_cloudwatch_logs | Deploy a CloudWatch agent daemon on every EC2 instance in this cluster.Tails host log files (/var/log/messages, /var/log/dmesg) into CloudWatch log groups.Does not affect container stdout/stderr, which is always shipped via the Dockerawslogs driver configured on the task definition. | bool | true | no |
| enable_dead_letter_queue | Create a dead-letter queue for the queue, named after it with "-dlq" (before ".fifo" on aFIFO queue), and an alarm on its depth, emailed to alert_notification_email. A messagereceived dead_letter_queue_max_receive_count times without being deleted moves there. Itexpires 14 days after it was first sent to the queue, so at least 10 days after the move, oron a FIFO queue 14 days after the move. Leave it off if you set a redrive policy on queue_urlyourself: the module's would replace it. | bool | false | no |
| enable_ecr_image_tagging | When enabled, a Lambda function tags deployed ECR images witha deployed-at-<timestamp> tag each time the consumer ECS servicereaches steady state. This protects the actively deployed imagefrom being pruned by the ECR lifecycle policy, so it remainsavailable for redeploys and rollbacks.Only affects images pulled from ECR (Docker Hub, public ECR, etc.are silently skipped). When true, consumer_docker_image must be anECR image URI. | bool | false | no |
| enable_vector_agent | Deploy a Vector Agent daemon on every EC2 instance in this cluster.Collects container logs (via Docker socket) and host metrics, forwards to aVector Aggregator. Requires vector_aggregator_endpoint or vector_agent_config. | bool | false | no |
| environment | Environment name string. | string | n/a | yes |
| fifo_queue | If true, the queue supports FIFO queue behavior. | bool | false | no |
| log_retention_days | Number of days you want to retain log events in a log group. | number | 365 | no |
| queue_name | Name of the queue. | string | null | no |
| service_name | A descriptive name for the service that owns the queue. | string | n/a | yes |
| tags | A map of tags to add to resources. | map(string) | {} | no |
| vector_agent_config | Custom Vector Agent config (YAML string). When provided, replaces thebuilt-in default config template entirely. | string | null | no |
| vector_agent_image | Vector Agent container image. | string | "timberio/vector:0.43.1-alpine" | no |
| vector_agent_task_policy_arns | List of IAM policy ARNs to attach to the Vector Agent task role.The default config (Docker logs + host metrics forwarded to an aggregator)needs no AWS permissions. Add policies here if your Vector config uses AWSsinks (S3, CloudWatch, Kinesis, etc.). | list(string) | [] | no |
| vector_aggregator_endpoint | Vector Aggregator address (host:port) for the agent to forward data to.Used by the default config template. Ignored if vector_agent_config is set.Example: "vector-aggregator.sandbox.tinyfish.io:6000" | string | null | no |
| ECS task execution role ARN |
| task_role_arn | ECS task role ARN |