
Beyond the Build Pipeline: Automating Container Image Vulnerability Monitoring on AWS
ECR | SECURITY I DEVSECOPS | AUTOMATION
Introduction
I had already included vulnerability scanning in the CI/CD pipeline for Project Orderly, a microservice application I deployed on Amazon EKS. Before I could push any image to Amazon ECR, it had to pass the Trivy security check.
I was excited to see it pass the security check because I thought that stage was done.
A few days later, I re-ran the same pipeline against the same codebase. I hadn’t changed anything in the application, yet Trivy now reported new vulnerabilities, and the pipeline failed. The images that had previously passed the scan were already sitting in ECR.
That moment raised a question the CI pipeline alone could not answer:
What happens to container images that are already sitting in ECR when new vulnerabilities become known?
I didn't want vulnerability monitoring to depend entirely on whether someone triggered a new build. That question led me to explore Amazon Inspector's Enhanced Scanning capability and the possibility of continuously assessing container images after they have been pushed.
Finding vulnerabilities was only part of what I wanted to achieve. I also needed a way to be notified when important findings appeared, without constantly checking the Inspector console.
In this project, I used Amazon Inspector, Amazon EventBridge, Amazon SQS, AWS Lambda, DynamoDB, and Amazon SNS to build an event-driven workflow that processes vulnerability findings and sends email notifications for high-severity and critical-severity issues.
I didn't introduce Inspector to replace Trivy but to extend the security checks beyond the CI/CD pipeline. Trivy helps me assess images during the build process, while Inspector provides ongoing visibility into images already pushed to ECR.
This article walks through how I built that workflow, the decisions I made along the way, and how I tested both successful event processing and failure handling using an SQS dead-letter queue.
It is intended for DevOps engineers, cloud engineers, and developers who want to understand how to build event-driven security monitoring workflows using AWS services.
What This Project Is (and What It Isn't)
Before getting into the implementation, it's worth clarifying what this project is designed to do.
Goal: To build an automated container vulnerability monitoring and management workflow using AWS services.
I wanted a way to continuously assess selected container images stored in Amazon ECR, identify vulnerability findings that require attention, keep track of those findings throughout their lifecycle, and notify the people responsible for investigating them.
Rather than relying on someone to manually check vulnerability reports across multiple repositories and images, the workflow automates the process of capturing Inspector events, filtering relevant findings, identifying the responsible owner, and maintaining a record of each finding as its status changes.
For this implementation, I focused on active High and Critical findings. This helps prioritise issues that may require more immediate attention without sending notifications for every finding reported by Inspector.
An important part of the workflow is ensuring that findings are associated with the correct ECR repository and image digest. This makes it possible to identify the affected image, determine who is responsible for it, and track changes to the finding over time.
However, detecting, tracking, and reporting vulnerabilities is different from fixing them.
What this project does
- Assesses selected container images in ECR using Amazon Inspector Enhanced Scanning
- Captures and routes Inspector events through EventBridge and SQS
- Filters for active
HighandCriticalfindings
- Associates findings with the responsible owner based on the ECR repository
- Stores received vulnerability findings in DynamoDB, including their repository, image digest, severity, and notification history
- Sends targeted notifications via SNS
- Retains failed events in dead-letter queues for investigation
What this project doesn’t do
- It does not automatically update dependencies, change Dockerfiles, or open pull requests.
- It does not trigger a new pipeline or redeploy images.
- It does not replace human investigation and remediation decisions
- Marking a finding as resolved does not prove that every running workload is using a fixed image
The intention is to automate more than just vulnerability detection and email notifications. I also want the workflow to maintain visibility into who is responsible for a finding and what happens to it after it is reported.
When a vulnerability is detected, the responsible engineer should be able to identify the affected image, investigate the reported issue, and determine the appropriate remediation. Once a fix is applied and a new image is pushed, subsequent Inspector events can be used to update the existing finding record when its status changes.
For example, if Inspector reports a vulnerability against an older image, pushing a newer image doesn't automatically mean the original finding has been resolved. The affected image digest still matters, and the older image may still be in use. By retaining finding records, the workflow provides better visibility into these situations.
Ultimately, the project is designed to automate vulnerability monitoring, ownership, tracking, and notification while keeping remediation decisions in the hands of the people responsible for the affected images.
Configuring Amazon ECR Enhanced Scanning with Terraform
Once I decided to use Amazon Inspector for continuous monitoring, the first step was enabling Enhanced Scanning on the images already stored in ECR.
I had four repositories, but I didn't necessarily want all four under continuous scanning. Enhanced scanning comes with a cost, so I wanted to be deliberate about which ones I included.
Instead of hard-coding repository names, I used the
aws_ecr_repositories data source so Terraform could discover what already existed in the account.data "aws_ecr_repositories" "existing" {}I then defined a
repositories_to_scan variable and used setintersection and setsubtract to validate the selection. This way, I could catch any names that didn't match the selected repositories before applying configuration.didn't match the selected repositories before applying configuration.
locals { existing_set = toset(data.aws_ecr_repositories.existing.names) valid_repositories = setintersection(var.repositories_to_scan, local.existing_set) invalid_repositories = setsubtract(var.repositories_to_scan, local.existing_set) }With the list validated, I used the
aws_ecr_registry_scanning_configuration resource and a dynamic repository_filter block to generate the filters.resource "aws_ecr_registry_scanning_configuration" "enhanced" { scan_type = "ENHANCED"
rule { scan_frequency = "CONTINUOUS_SCAN"
dynamic "repository_filter" { for_each = local.valid_repositories
content { filter = repository_filter.value filter_type = "WILDCARD" } } }
lifecycle { precondition { condition = length(local.invalid_repositories) == 0 error_message = "The following ECR repositories do not exist: ${join(", ", tolist(local.invalid_repositories))}" } }}This configured Amazon ECR Enhanced Scanning for the three selected repositories, enabling Amazon Inspector to continuously assess their container images for vulnerabilities.
Note:
WILDCARD is the only filter type ECR supports. A value with no * acts as an exact match.For Orderly, I selected three repositories:
-
orderly-apigateway
-
orderly-frontend
-
orderly-notifier
I deliberately left it out
orderly-orderworker to test whether my Terraform configuration could selectively enable enhanced scanning for specific ECR repositories. You can find the full Terraform configuration in the project repository .Screenshot of all 4 repos created

Screenshot of three repos utilising the enhanced scanning feature

Balancing Container Security with AWS Costs
Enhanced Scanning is useful because Inspector keeps assessing images that are already in ECR. It also has a cost after the 15-day trial.
For this project, my main goal was to build and test the notification workflow, not design a long-term cost strategy. In a real environment, teams would need to decide whether continuous monitoring is required all the time, or whether it makes more sense to enable Enhanced Scanning only during scheduled security reviews.
One possible approach is to manage the scanning mode through Terraform:
- Switch to
ENHANCEDat the start of a review cycle
- Let Inspector assess the images and surface findings
- Remediate and push updated images
- Switch back to
BASICscanning once the review is complete.
This keeps the code change instead of relying on manual console updates. The trade-off is clear: once Enhanced Scanning is turned off, any vulnerability that appears between review cycles will not be detected until the next assessment.
Whether continuous monitoring or periodic reviews make more sense depends on the organisation’s risk tolerance and how critical the workloads are.
Routing Amazon Inspector Events with Amazon EventBridge
With Enhanced Scanning enabled, Amazon Inspector begins assessing the selected images and generating findings.
The next problem was getting those findings out of Inspector and into the rest of the workflow without constantly polling the console.
That’s where EventBridge came in.
I created two rules.
The first rule, called
orderly-inspector-scan-events , captures scan-completion events ( INITIAL_SCAN_COMPLETE ). I wanted a record of when an initial scan finished.event_pattern = jsonencode({ source = ["aws.inspector2"] detail-type = ["Inspector2 Scan"] detail = { scan-status = ["INITIAL_SCAN_COMPLETE"] }})The second rule, called
orderly-inspector-vulnerability-findings is more selective. It only matches findings that are both ACTIVE and either HIGH or CRITICAL . I didn’t want every finding to generate a notification; only the ones that actually needed attention.event_pattern = jsonencode({ source = ["aws.inspector2"] detail-type = ["Inspector2 Finding"] detail = { severity = ["HIGH", "CRITICAL"]
status = ["ACTIVE"] } }) Both rules send matching events to the same SQS queue. This keeps the downstream processing simple while still allowing the two event types to be handled differently if needed later.
resource "aws_cloudwatch_event_target" "inspector_findings" { rule = aws_cloudwatch_event_rule.first_rule.name target_id = "InspectorScanEventsQueue" arn = var.main_queue_arn}
resource "aws_cloudwatch_event_target" "inspector_vulnerability_findings" { rule = aws_cloudwatch_event_rule.second_rule.name target_id = "InspectorVulnerabilityEventsQueue" arn = var.main_queue_arn}Event Delivery Retry Policy
When EventBridge attempts to deliver an event to an SQS target, delivery may fail for reasons such as temporary service interruptions or permission issues.
Rather than abandoning the event, EventBridge uses an automatic retry mechanism with exponential backoff to handle failed deliveries.
EventBridge allows you to configure two retry limits: the maximum time an event can remain eligible for retries and the maximum number of retry attempts.
Since this is a solo project, I configured EventBridge to retry failed deliveries for up to 1 hour (3,600 seconds). If EventBridge cannot deliver an event within these limits, it sends the event to the dedicated EventBridge delivery dead-letter queue.
In a production environment, I would retain AWS's default retry policy of 24 hours and up to 185 attempts, giving operations teams a longer recovery window to resolve the issues.
resource "aws_cloudwatch_event_target" "inspector_findings" { rule = aws_cloudwatch_event_rule.first_rule.name target_id = "InspectorScanEventsQueue" arn = var.main_queue_arn
# Configure how EventBridge retries failed deliveries retry_policy { maximum_event_age_in_seconds = 60 # 3600 #1hour maximum_retry_attempts = 0 #10 # Set your chosen retry cap }
# Send events to the delivery DLQ if EventBridge # cannot deliver them to the main SQS queue dead_letter_config { arn = var.ddlq_arn }}
resource "aws_cloudwatch_event_target" "inspector_vulnerability_findings" { rule = aws_cloudwatch_event_rule.second_rule.name target_id = "InspectorVulnerabilityEventsQueue" arn = var.main_queue_arn
# Configure how EventBridge retries failed deliveries retry_policy { maximum_event_age_in_seconds = 3600 # 1 hour maximum_retry_attempts = 10 # Set your chosen retry cap }
# Send events to the delivery DLQ if EventBridge # cannot deliver them to the main SQS queue dead_letter_config { arn = var.ddlq_arn }}Controlling access to the SQS queues
Creating the EventBridge targets is not enough. The SQS queue still needs permission to accept messages from EventBridge.
I used a resource-based policy that grants the EventBridge service principal permission to call
sqs:SendMessage on the main queue. I also restricted the policy with a aws:SourceArn condition so that only the two specific rules I created can send messages.data "aws_iam_policy_document" "eventbridge_main_sqs" { statement { sid = "AllowEventBridgeRules" effect = "Allow"
principals { type = "Service" identifiers = ["events.amazonaws.com"] }
actions = [ "sqs:SendMessage" ]
resources = [ var.main_queue_arn ]
condition { test = "ArnEquals" variable = "aws:SourceArn"
values = [ var.inspector_findings_arn, var.inspector_findings_vulnerability_arn ] } }}
resource "aws_sqs_queue_policy" "eventbridge_sqs" { queue_url = var.main_queue_url policy = data.aws_iam_policy_document.eventbridge_main_sqs.json}I applied the same pattern to the EventBridge delivery dead-letter queue. This ensures that if EventBridge exhausts its delivery attempts, those events can still land in the dedicated delivery DLQ, but only from the authorised rules.
data "aws_iam_policy_document" "eventbridge_delivery_dlq_policy" { statement { sid = "AllowEventBridgeDLQDelivery" effect = "Allow"
principals { type = "Service" identifiers = ["events.amazonaws.com"] }
actions = [ "sqs:SendMessage" ]
resources = [ var.ddlq_arn ]
condition { test = "ArnEquals" variable = "aws:SourceArn"
values = [ var.inspector_findings_arn, var.inspector_findings_vulnerability_arn ] } }}
resource "aws_sqs_queue_policy" "eventbridge_dlq" { queue_url = var.ddlq_url policy = data.aws_iam_policy_document.eventbridge_delivery_dlq_policy.json }Buffering Inspector Events and Handling Failures with Amazon SQS
EventBridge can deliver events, but I didn’t want processing to depend on Lambda being immediately available. That’s why I introduced SQS.
I created two queues:
-
orderly-inspector-events; the main queue that receives events from both EventBridge rules
-
orderly-inspector-dlq; the dead-letter queue for messages that cannot be processed
The main queue has a visibility timeout of 180 seconds and a redrive policy that moves a message to the DLQ after three failed receive attempts. This prevents a bad message from being retried forever.
I set the DLQ retention to four days. Because this is a solo project and I’m the only person checking the queues, four days was enough time for me to notice and investigate. In a production environment with a team, a longer retention (up to the 14-day maximum) is safer.
resource "aws_sqs_queue" "main_queue" { name = var.main_queue delay_seconds = 0 max_message_size = 262144 message_retention_seconds = var.mq_message_retention_in_seconds receive_wait_time_seconds = 0 visibility_timeout_seconds = 180 redrive_policy = jsonencode({ deadLetterTargetArn = aws_sqs_queue.dlq_queue.arn maxReceiveCount = var.maxReceiveCount })
tags = { Environment = var.environment }}I also created a separate dead-letter queue for EventBridge delivery failures.
- The EventBridge delivery DLQ catches events that never reached the main queue.
resource "aws_sqs_queue" "eventbridge_delivery_dlq" { name = var.eventbridge_delivery_dlq message_retention_seconds = var.ddlq_message_retention_in_seconds delay_seconds = 0 max_message_size = 262144 receive_wait_time_seconds = 0
tags = { Environment = var.environment }}- The SQS processing DLQ catches messages that reached the queue but could not be processed by Lambda.
resource "aws_sqs_queue" "dlq_queue" { name = var.dlq_queue fifo_queue = false delay_seconds = 0 max_message_size = 262144 message_retention_seconds = var.dlq_message_retention_in_seconds receive_wait_time_seconds = 0 visibility_timeout_seconds = 30
tags = { Environment = var.environment }}Successful delivery is not the same as successful processing. Keeping the two failure paths separate made that clearer.
Processing Inspector Findings with AWS Lambda
Once events were landing in SQS, I needed something to process them. I used a Python Lambda function
orderly-inspector-processor triggered by the main queue.The function does several things:
- Determines whether the event is a scan completion or a vulnerability finding
- Extracts the repository name, image digest, severity, and other relevant details
- Looks up the responsible owner based on the repository
- Writes or updates a record in DynamoDB so the finding can be tracked over time
- Publishes a notification to SNS when the finding meets the severity criteria
I deliberately put this logic in Lambda rather than trying to do everything inside EventBridge rules. It gave me a single place to add processing logic without making the event patterns overly complex.
Storing Vulnerability Findings in Amazon DynamoDB
After processing an event, the Lambda function stores the finding in DynamoDB.
I added DynamoDB because I wanted more than a one-time notification. I wanted a persistent record of each finding, which repository and image digest it belonged to, who owned it, whether a notification had been sent, and how its status changed over time.
A
SENT status means SNS accepted the publish request. It does not guarantee the email reached the recipient’s inbox. Keeping that distinction in the record makes debugging clearer later.Is DynamoDB strictly necessary? If the only goal was to forward alerts, then no. But once you want ownership, history, and the ability to see what happened to a finding after it was first reported, some form of persistent store becomes useful. The cost of that store has to be justified by the visibility it provides.
Distributing Vulnerability Alerts with Amazon SNS
After a finding is processed and recorded, the Lambda function publishes a message to an SNS topic
orderly-inspector-alerts .I used SNS so that notification delivery stayed decoupled from the processing logic. The Lambda function doesn’t need to know how to send individual emails; it just publishes a message with the relevant attributes.
Those attributes are used by SNS subscription filter policies. This allows different people or teams to receive only the alerts that are relevant to them, rather than every High and Critical finding going to everyone.
The Lambda function builds a set of recipients for each finding based on four roles:
- Review owner: The person who initiated the scan.
- Security specialist and Engineering lead: These are oversight roles. The security specialist receives emails for all vulnerabilities detected. The engineering lead receives emails only for vulnerabilities with Critical findings.
- Repository owner team: The team that owns the repository (Frontend or Backend in my setup). They are notified so they are aware that a vulnerability exists in their codebase, even if someone else will fix it.
- Remediation team: The team responsible for actually fixing the issue. This is determined by the type of vulnerability:
- Application dependencies are normally routed to the repository’s own team.
- Operating-system / base-image packages are routed to the Platform/DevOps team.
- Anything that cannot be clearly classified goes to manual triage.
This separation is deliberate. If a backend repository has an OS-level vulnerability that DevOps can fix, the backend owners still need to know that work is happening in their repository. Leaving them out of the loop would create ownership problems.
One important distinction remains: a successful publish to SNS is not the same as confirmed email delivery. The system records that SNS accepted the message. Whether the email actually reaches the recipient’s inbox is a separate step that depends on the subscription being confirmed and the message successfully being delivered.
Testing Vulnerability Notifications and Email Delivery
After confirming that findings were being detected and stored correctly, I tested whether the right people actually received the alerts.
During testing, I temporarily used personal email addresses as the SNS subscribers.
In a production environment, the personal addresses would be replaced with team mailboxes. The routing logic itself stays the same.
Screenshot of one of the emails received

Testing SQS Retries and Dead-Letter Queue Handling
During testing, I ran into a problem with the Lambda function. Messages were reaching the function, but they were not being processed successfully, so nothing was making it to SNS.
When I checked the main SQS queue, it showed zero messages. At first glance, it looked like the events had simply disappeared. CloudWatch Logs told a different story; the function failed repeatedly while trying to process the messages.
After the configured number of retries, the messages were moved to the processing dead-letter queue. When I checked the DLQ, the failed messages were there.
This confirmed that the retry policy and dead-letter queue were doing their job: messages that could not be processed were isolated instead of being lost or retried indefinitely.
Screenshot of Main SQS queue showing zero messages

Screenshot of CloudWatch Logs showing the processing failures

Screenshot of Processing DLQ showing nine messages

The receive counts shown in the SQS console are higher than the number of failed processing attempts because manually polling messages through the console also increments their receive count.
Testing the EventBridge Delivery DLQ
I also wanted to confirm that events would not simply disappear if EventBridge failed to deliver them to the SQS queue.
The SQS processing DLQ only handles messages that already reached the queue but then failed during Lambda processing. The EventBridge delivery DLQ covers a different failure: events that never make it to the queue in the first place.
Setting up the test
I attached a dead-letter queue called
orderly-eventbridge-delivery-dlq to the EventBridge rule targets.To make the test practical, I temporarily changed the retry policy in Terraform:
retry_policy { maximum_event_age_in_seconds = 60 maximum_retry_attempts = 0}With zero retries and a short maximum age, failed deliveries would move to the DLQ quickly instead of retrying for hours.
Causing a real delivery failure
I pushed an older Alpine image
alpine:3.14 to the orderly-frontend repository so Inspector would generate real events.I then removed the permission that allows EventBridge to call
sqs:SendMessage on the target queue. When a matching Inspector event arrived, EventBridge had nowhere to deliver it.Checking the delivery DLQ
I opened the
orderly-eventbridge-delivery-dlq queue and polled for messages. Two messages were waiting.

Looking at the message attributes showed exactly why delivery had failed:

The
NO_PERMISSIONS error, together with the rule and target ARNs, made the root cause obvious. This test confirmed that the delivery DLQ successfully captured events that EventBridge could not hand off.Testing Vulnerability Remediation and Notification Behaviour
Fixing the Platform End of Life finding
During the initial scan, Amazon Inspector raised a Critical finding against the orderly-frontend image.
The finding was titled “Platform End of Life” with vulnerability ID
IN-DISCONTINUED-001 . It pointed to the operating system used in the runtime stage of the image.

After checking the Dockerfile, I found that the runtime was based on an older Alpine Linux release. I updated it to a newer nginx-unprivileged image built on Alpine Linux 3.24, committed the change, and re-ran the CI/CD pipeline, so the new image was built and pushed to ECR.
Once the new image was in the registry, I checked its digest and confirmed that Inspector had scanned it successfully. I then specifically looked for the
IN-DISCONTINUED-001 finding against the new digest. Nothing came back.Screenshot showing the latest image in orderly-frontend

Screenshot showing the vulnerability no longer exists using the new image digest

What happens after a developer fixes a vulnerability
A natural question is whether a developer needs to manually trigger another scan after making a fix.
The short answer is no. The developer’s responsibility is to investigate the finding, make the necessary changes, and push a new image. Once that image lands in ECR, Inspector will assess it.
The cycle looks like this:
- Inspector identifies a vulnerability.
- The system records the finding and notifies the responsible team.
- The developer investigates and makes the change.
- A new image is built and pushed to ECR.
- Inspector scans the new image.
- The system evaluates the results and only sends a notification if High or Critical findings are still present.
Note: Confirmation should always be done against the new image digest.
Why keep vulnerability records after remediation
Even after a finding is fixed, the historical record still has value.
Security teams often need to answer questions such as:
- Which vulnerabilities appeared before?
- Which repositories and image digests were affected?
- Who was responsible for the remediation?
- When was the finding first detected and when was it resolved?
- Did the same issue reappear later?
- How long did remediation take?
These records do not need to live forever. Retention should follow the organisation’s security and compliance policy. Deleting everything simply because the current set of findings has been resolved removes useful history.
Conclusion
This project started with a question: what happens to container images that are already stored in ECR when new vulnerabilities are discovered?
I initially approached the problem from the perspective of continuous vulnerability scanning. But as I worked through the implementation, I realised that detecting a vulnerability was only one part of the problem.
I needed a way to capture findings, process them reliably, identify the affected repository, determine who should investigate the issue or remediate the issue, maintain records of received findings, and notify the appropriate people.
By combining Amazon Inspector, EventBridge, SQS, Lambda, DynamoDB, and SNS, I have been building a workflow that addresses those responsibilities.
One important design decision was separating repository ownership from remediation responsibility. The team that owns a repository may not necessarily be the team responsible for fixing every vulnerability in its container image. My notification workflow accounts for that distinction.
One of my biggest lessons from this project is that security automation should not stop at detection. A finding is more useful when it has context, an owner, a remediation path, and a process for keeping relevant people informed.
The workflow does not automatically fix vulnerabilities. Instead, it makes findings visible, routes them to the appropriate teams, and provides the information they need to investigate and remediate them.
And that, for me, is what it means to go beyond the build pipeline.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article