Deploy a ChatOps solution to manage SAST scan results by using AWS Chatbot custom actions and AWS CloudFormation
Created by Anand Bukkapatnam Tirumala (AWS)
Summary
This pattern presents a comprehensive solution that uses AWS Chatbot to streamline the management of static application security testing (SAST) scan failures reported through SonarQube. This innovative approach integrates custom actions and notifications into a conversational interface, enabling efficient collaboration and decision-making processes within development teams.
In today's fast-paced software development environment, managing SAST scan results efficiently is crucial for maintaining code quality and security. However, many organizations face the following significant challenges:
Delayed awareness of critical vulnerabilities because of inefficient notification systems
Slow decision-making processes caused by disconnected approval workflows
Lack of immediate, actionable responses to SAST scan failures
Fragmented communication and collaboration around security findings
Time-consuming and error-prone manual infrastructure setup for security tooling
These issues often lead to increased security risks, delayed releases, and reduced team productivity. To address these challenges effectively requires a solution that can streamline SAST result management, enhance team collaboration, and automate infrastructure provisioning.
Key features of the solution include:
Customized notifications – Real-time alerts and notifications are delivered directly to team chat channels, ensuring prompt awareness and action on SAST scan vulnerabilities or failures.
Conversational approvals – Stakeholders can initiate and complete approval workflows for SAST scan results seamlessly within the chat interface, accelerating decision-making processes.
Custom actions – Teams can define and execute custom actions based on SAST scan outcomes, such as automatically triggering email messages for quality gate failures, enhancing responsiveness to security issues.
Centralized collaboration – All SAST scan-related discussions, decisions, and actions are kept within a unified chat environment, fostering improved collaboration and knowledge-sharing among team members.
Infrastructure as code (IaC) – The entire solution is wrapped with AWS CloudFormation templates, enabling faster and more reliable infrastructure provisioning while reducing manual setup errors.
Prerequisites and limitations
Prerequisites
An active AWS account.
An AWS Identity and Access Management (IAM) role with permissions to create and manage resources associated with the AWS services listed in Tools.
A Slack workspace.
AWS Chatbot added to the required Slack workspace as a plugin. For more information, see Add apps to your Slack workspace
in the Slack documentation. Keep a note of the Slack workspace ID as shown on the AWS Management Console after successful registration. A configured AWS Chatbot client, with the workspace ID readily available for input in the AWS CloudFormation console. For instructions, see Configure a Slack client in the AWS Chatbot Administrator Guide.
A source email account that is created and verified in Amazon Simple Email Service (Amazon SES) to send out approval email messages. For setup instructions, see Creating and verifying email identities in the Amazon Simple Email Service Developer Guide.
A destination email address for receiving approval notifications. This address can be a shared inbox or a specific team distribution list.
An operational SonarQube instance that’s accessible from your AWS account. For more information, see the SonarQube installation instructions
. A SonarQube user token
with permissions to trigger and create projects through the pipeline.
Limitations
Custom actions for AWS Chatbot are currently not supported through AWS CloudFormation. The creation of custom action buttons is a manual process in this solution.
Some AWS services aren’t available in all AWS Regions. For Region availability, see AWS services by Region
. For specific endpoints, see Service endpoints and quotas, and choose the link for the service.
Architecture
The following diagram shows the workflow and architecture components for this pattern.
The diagram shows the automated code quality assurance workflow:
Code preparation and upload:
The developer compresses the codebase into a .zip file.
The developer manually uploads the .zip file to a designated Amazon Simple Storage Service (Amazon S3) bucket.
Amazon S3 event trigger and AWS Step Functions orchestration:
The Amazon S3 upload event triggers a Step Functions workflow.
Step Functions orchestrates a SAST scan using SonarQube.
The workflow monitors the AWS CodeBuild job status to determine next actions. If CodeBuild succeeds (quality gate pass), the workflow terminates. If CodeBuild fails, an AWS Lambda function is invoked for diagnostics. For more details, see AWS Step Functions logic later in this section.
AWS CodeBuild execution:
The CodeBuild job executes a SonarQube scan on the uploaded codebase.
Scan artifacts are stored in a separate Amazon S3 bucket for auditing and analysis.
Failure analysis (Lambda function):
On CodeBuild failure, the
CheckBuildStatus
Lambda function is triggered.On CodeBuild success, the process is terminated and no further action is needed.
Lambda function analyzes failure cause (quality gate failure or other issues)
The
CheckBuildStatus
function creates a custom payload with detailed failure information.The
CheckBuildStatus
function publishes the custom payload to an Amazon Simple Notification Service (Amazon SNS) topic.
Notification system:
Amazon SNS forwards the payload to AWS Chatbot for Slack integration.
Slack integration:
AWS Chatbot posts a notification in the designated Slack channel.
Approval process:
Approvers review the failure details in the Slack notification.
Approvers can initiate approval using the Approve button in Slack.
Approval handler:
An Approval Lambda function processes the approval action from Slack.
The Approval function generates a custom message for developer notification.
The Approval function publishes the custom message to Amazon SES.
Developer notification:
Amazon SES sends an email message to the developer with next steps or required actions.
This workflow combines manual code upload with automated quality checks, provides immediate feedback through Slack, and allows for human intervention when necessary, ensuring a robust and flexible code review process.
AWS Step Functions logic
As shown in the previous architecture diagram, if the quality gate pass on SonarQube fails, the workflow goes to the CheckBuildStatus
Lambda function. The CheckBuildStatus
function triggers a notification on the Slack channel. Each notification includes information with suggested next steps. Following are the types of notifications:
Application has failed in code security scan – The user receives this notification when the uploaded code did not pass the SonarQube security scan. The user can choose APPROVE to accept the build. However, the notification advises the user to beware of potential poor code quality and security risks. The notification includes the following details:
Next steps: Error: Quality gate status: FAILED – View details at the provided URL.
Triage the vulnerabilities as mentioned in the document at the provided URL.
CodeBuild details are available at the location at the provided URL.
Application scan pipeline has failed because of some other reason – The user receives this notification when the pipeline failed for some reason other than failing the code security scan. The notification includes the following details:
For next steps, go to the link provided for further troubleshooting.
To see screenshots of the notifications as they appear in a Slack channel, go to the assets folder
The following diagram shows an example of Step Functions step status after the quality gate pass fails.
Tools
AWS services
AWS Chatbot enables you to use Amazon Chime, Microsoft Teams, and Slack chat channels to monitor and respond to operational events in your AWS applications.
AWS CloudFormation helps you set up AWS resources, provision them quickly and consistently, and manage them throughout their lifecycle across AWS accounts and AWS Regions.
AWS CodeBuild is a fully managed build service that helps you compile source code, run unit tests, and produce artifacts that are ready to deploy.
AWS Identity and Access Management (IAM) helps you securely manage access to your AWS resources by controlling who is authenticated and authorized to use them.
AWS Key Management Service (AWS KMS) helps you create and control cryptographic keys to help protect your data.
AWS Lambda is a compute service that helps you run code without needing to provision or manage servers. It runs your code only when needed and scales automatically, so you pay only for the compute time that you use.
AWS Secrets Manager helps you replace hardcoded credentials in your code, including passwords, with an API call to Secrets Manager to retrieve the secret programmatically.
Amazon Simple Email Service (Amazon SES) helps you send and receive email messages by using your own email addresses and domains.
Amazon Simple Notification Service (Amazon SNS) helps you coordinate and manage the exchange of messages between publishers and clients, including web servers and email addresses.
Amazon Simple Storage Service (Amazon S3) is a cloud-based object storage service that helps you store, protect, and retrieve any amount of data.
AWS Step Functions is a serverless orchestration service that helps you combine AWS Lambda functions and other AWS services to build business-critical applications.
Other tools
Slack
, a Salesforce offering, is an AI-powered conversational platform that provides chat and video collaboration, automates processes with no code, and supports information sharing. SonarQube
is an on-premises analysis tool designed to detect coding issues in over 30 languages, frameworks, and IaC platforms.
Code repository
The code for this pattern is available in the GitHub chatops-slack
Best practices
CloudFormation stack management – If you encounter any failures during CloudFormation stack execution, we recommend that you delete the failed stack. Then, re-create it with the correct parameter values. This approach supports a clean deployment and helps avoid potential conflicts or partial implementations.
Shared inbox email configuration – When you configure the
SharedInboxEmail
parameter, use a common distribution list that’s accessible to all relevant developers. This approach promotes transparency and helps important notifications reach the relevant team members.Production approval workflow – For production environments, restrict access to the Slack channel that’s used for build approvals. Only designated approvers should be members of this channel. This practice maintains a clear chain of responsibility and enhances security by limiting who can approve critical changes.
IAM permissions – Follow the principle of least privilege and grant the minimum permissions required to perform a task. For more information, see Grant least privilege and Security best practices in the IAM documentation.
Epics
Task | Description | Skills required |
---|---|---|
Clone the repository. | To clone the chatops-slack
| AWS DevOps, Build lead, DevOps engineer, Cloud administrator |
Create the .zip files that contain Lambda code. | Create the .zip files for the AWS Lambda function code for the
| AWS DevOps, Build lead, DevOps engineer, Cloud administrator |
Task | Description | Skills required |
---|---|---|
Execute the | The
| AWS administrator, AWS DevOps, Build lead, DevOps engineer |
Upload the .zip files to the Amazon S3 bucket. | Upload the | AWS DevOps, Build lead, DevOps engineer, AWS systems administrator |
Task | Description | Skills required |
---|---|---|
Execute the | The
| AWS DevOps, AWS systems administrator, DevOps engineer, Build lead |
Test the notification setup. | To test the notification setup, do the following:
After the test message is delivered successfully, you should see a notification on the Slack channel. For more information, see Test notifications from AWS services to Slack in the AWS Chatbot Administrator Guide. | AWS DevOps, AWS systems administrator, DevOps engineer, Build lead |
Task | Description | Skills required |
---|---|---|
Configure custom Lambda action. | To set up the custom AWS Lambda action, do the following:
| AWS administrator, AWS DevOps, Build lead, DevOps engineer, Slack Admin |
Validate approval flow. | To validate that the approval flow works as expected, choose the Approve button in Slack. Slackbot should send a notification on the message thread with the confirmation string Approval Email sent successfully. | AWS administrator, AWS DevOps, DevOps engineer, Slack Admin |
Troubleshooting
Issue | Solution |
---|---|
Slack misconfigurations | For information about troubleshooting issues related to Slack misconfigurations, see Troubleshooting AWS Chatbot in the AWS Chatbot Administrator Guide. |
Scan failed because of some other reason | This error means that the code build task has failed. To troubleshoot the issue, go to the link that’s in the message. The failure of the code build task might have the following possible causes:
|
Related resources
AWS documentation
Other resources
Add apps to your Slack workspace
(Slack documentation) Generating and using tokens
(SonarQube documentation) Introduction to the server installation
(SonarQube documentation)
Additional information
This solution emphasizes AWS Chatbot custom actions for release management purposes. However, you can reuse the solution by modifying the Lambda code for your specific use case and build on top of it.
Parameters of CloudFormation stack files
The following table shows the parameters and their descriptions for the CloudFormation stack file pre-requisite.yml
.
Key | Description |
---|---|
| The name of the CloudFormation stack. |
| The name of the Amazon S3 bucket where you upload the Lambda code. The name must be globally unique. |
| The SonarQube user token as described in Prerequisites. |
The following table shows the parameters and their descriptions for the CloudFormation stack file app-security.yml
.
Key | Description |
---|---|
| The AWS KMS key Amazon Resource Name (ARN) that is used in IAM roles and Lambda functions created in this stack. |
| The AWS KMS key ID that is used in the Amazon SNS topic created in this stack. |
| The name of the client environment for deployment of the application scan pipeline. Select the environment name from the dropdown list of allowed values. |
| The name of the Amazon S3 bucket that contains the |
| The name of the registered email identity in Amazon SES as described in Prerequisites. This identity is the source email address. |
| The destination email address to which the scan notifications are sent. |
| The channel ID of the Slack channel where you want the notifications sent. To find the channel ID, right-click the channel name in Channel Details on the Slack app. The channel ID is at the bottom. |
| The Slack workspace ID as described in Prerequisites. To find the Slack workspace ID, sign in to the AWS Management Console, open the AWS Chatbot console, and choose Configured clients, Slack, WorkspaceID. |
| The name of the CloudFormation stack. |
| The directory that contains the |
| The name of the |
| The name of the .zip file that contains the |