• DevOps
    Case Study

    How we built a resilient multi-account, multi-cloud solution for a Health Tech service provider!

    READ CASESTUDY
    icon

    24/7 DevOps as a Service

    Round-the-clock DevOps for uninterrupted efficiency.

    icon

    Infrastructure as a Code

    Crafting infrastructure with ingenious code.

    icon

    CI/CD Pipeline

    Automated CI/CD pipeline for seamless deployments.

    icon

    DevSecOps

    Integrated security in continuous DevOps practices.

    icon

    Hire DevOps Engineers

    Level up your team with DevOps visionaries.

    icon

    Consulting Services

    Navigate success with expert DevOps consulting.

  • TechOps
    Case Study

    How we built a scalable Odoo solution for a Travel Tech service provider!

    READ CASESTUDY

    WEB HOSTING SUPPORT

    icon

    HelpDesk Support

    Highly skilled 24/7 HelpDesk Support

    icon

    Product Support

    Boost your product support with our expertise.

    MANAGED SERVICES

    icon

    Server Management

    Don’t let server issues slow you down. Let us manage them for you.

    icon

    Server Monitoring

    Safeguard your server health with our comprehensive monitoring solutions.

    STAFF AUGMENTATION

    icon

    Hire an Admin

    Transform your business operations with our expert administrative support.

    icon

    Hire a Team

    Augment your workforce with highly skilled professionals from our diverse talent pool.

  • CloudOps
    Case Study

    How we helped a Private Deemed University in India, save US $3500/m on hosting charges!

    READ CASESTUDY
    icon

    AWS Well Architected Review

    Round-the-clock for uninterrupted efficiency

    icon

    Optimize

    Efficient CloudOps mastery for seamless cloud management

    icon

    Manage

    Automated CI/CD pipeline for seamless deployments

    icon

    Migrate

    Upgrade the journey, Migrate & Modernize seamlessly

    icon

    Modernize

    Simplify compliance complexities with our dedicated services

    icon

    FinOps as a Service

    FinOps as a Service

  • SecOps
    Case Study

    How we built a scalable Odoo solution for TravelTech service provider!

    READ CASESTUDY
    icon

    VAPT

    Vulnerability Assessment and Penetration Testing

    icon

    Source Code Review

    Ensuring source code security ans safe practices to reduce risks

    icon

    Security Consultation

    On demand services for improving server security

    icon

    System Hardening

    Reduced vulnerability and proactive protection

    icon

    Managed SoC

    Monitors and maintains system security. Quick response on incidents.

    icon

    Compliance as a Service

    Regulatory compliance, reduced risk

  • Insights
    Case Study

    How we helped a Private Deemed University in India, save US $3,500/m on hosting charges!

    READ CASESTUDY
    icon

    Blog

    Explore our latest articles and insights

    icon

    Case Studies

    Read about our client success stories

    icon

    Flipbook

    Explore our latest Flipbook

    icon

    Events

    Join us at upcoming events and conferences

    icon

    Webinars

    Watch our educational webinar series

  • Our Story
  • Contact Us

Interested to collaborate?

Get in touch with us!

Ready to elevate your business with certified cloud expertise? Contact us today to learn how our team can help you leverage cloud technology to drive growth, streamline operations, and enhance security.

  • AWSAWS
  • Azure CloudAzure Cloud
  • Google CloudGoogle Cloud
  • Akamai CloudAkamai Cloud
  • OVHOVH
  • Digital OceanDigital Ocean
  • HetznerHetzner
  • Kubernetes Consultancy Services
  • K8s & Cloud native Solutions
  • 24/7 Infrastructure Monitoring
  • DevOps as a Service
  • Cloud CI/CD Solutions
  • White Labeled MSP Support
  • Our story
  • Life@SupportSages
  • Insights
  • Careers
  • Events
  • Contact Us

Connect with us!


LinkedInFacebookXInstagramYouTube

aws partneraws advanced partner
SupportSages

Copyright © 2008 – 2026 SupportSages Pvt Ltd. All Rights Reserved.
Privacy PolicyLegal TermsData ProtectionCookie Policy
Manual Approval in AWS CodePipeline with Lambda and SNS

Manual Approval in AWS CodePipeline with Lambda and SNS

Arya P B

  • 5 min read
Manual Approval in AWS CodePipeline with Lambda and SNS

Generating audio, please wait...

Introduction

Welcome to our guide on implementing a manual approval process in AWS CodePipeline using the powerful combination of Lambda functions and Simple Notification Service (SNS). In this blog post, we’ll walk you through the setup, allowing you to add a human touch to your automated deployment process.

Prerequisites

Before we dive in, make sure you have the following prerequisites:

  • AWS Account
  • AWS CodePipeline configured with at least one pipeline
  • Basic understanding of AWS Lambda and SNS

Overview

Let’s break down the high-level overview of the setup:

Detecting CodePipeline State Changes using EventBridge:

  • Utilize EventBridge to trigger actions based on changes in your CodePipeline’s execution state, specifically when it reaches a “SUCCEEDED” state.

Creating an SNS Topic for Sending Email Notifications:

  • Set up an SNS topic to streamline the process of sending email notifications.

Sending Email Notifications for Manual Approval using Lambda and SNS:

  • Walk through a Lambda function responsible for extracting pipeline names, constructing approval and rejection URLs, and seamlessly sending notifications through SNS.

Accepting or Rejecting the Manual Approval using Another Lambda Function:

  • Dive into a second Lambda function designed to take action based on the approval or rejection URLs. Learn how to extract pipeline names, action types, and trigger CodePipeline accordingly.

Create an SNS Topic

Let’s create an SNS topic to facilitate email notifications. Follow these steps:

  • Navigate to the SNS service in the AWS Management Console.
  • Create a new topic and note the ARN.

EventBridge Rule

Set up an EventBridge rule to trigger the Lambda function when the CodePipeline execution state changes to “SUCCEEDED.”

{
"source": ["aws.codepipeline"],
"detail-type": ["CodePipeline Pipeline Execution State Change"],
"detail": {
"state": ["SUCCEEDED"],
"pipeline": ["YourPipelineName"]
}
}

Lambda for Sending Email Notification

Explore the Lambda function responsible for sending email notifications. This includes extracting pipeline names, constructing URLs, and utilizing SNS for smooth communication.

import boto3
import json

def lambda_handler(event, context):
print(event)
sns_client = boto3.client('sns')
sns_topic_arn = " " # add arn of sns
pipeline_name = event['detail']['pipeline']

print("Pipeline Name:", pipeline_name)

# Include pipeline name in the URLs
url_base = " " //replae with acion lambda function url
approval_url = f"{url_base}?pipeline={pipeline_name}&action=approve"
rejection_url = f"{url_base}?pipeline={pipeline_name}&action=reject"

print("Approval URL:", approval_url)
print("Rejection URL:", rejection_url)

# Message content with approval and rejection URLs
message = f"CodePipeline name: {pipeline_name}\n\n"
message += f"Click the following URL to approve: {approval_url}\n"
message += f"Click the following URL to reject: {rejection_url}\n"

# Publish the message to SNS
sns_client.publish(
TopicArn=sns_topic_arn,
Message=message,
Subject=f"CodePipeline Approval/Rejection Options"
)

return {
'statusCode': 200,
'body': f'Successfully listed CodePipelines.',
}

Lambda for Taking Action

Delve into the second Lambda function designed to take action based on the approval or rejection URLs. Extract pipeline names, action types, and trigger CodePipeline accordingly.

import json
import boto3

def lambda_handler(event, context):
print("Event:", event)

client = boto3.client('codepipeline')
# Extract pipeline name from URL parameters
parameters = event['queryStringParameters']
pipeline_name = parameters.get('pipeline', None)
action = parameters.get('action', None)
pipelineName = pipeline_name
stage_name, action_name = get_manual_approval_details(pipelineName)
print(stage_name)
print(action_name)
stage_name = stage_name
action_name = action_name

token = get_approval_token(pipelineName, stage_name, action_name)
print(f"Approval Token: {token}")

approval_token = token

if pipeline_name:
# Trigger the CodePipeline
if action == 'approve':
# Provide approval result (Approved in this example)
response = client.put_approval_result(
pipelineName=pipeline_name,
stageName=stage_name,
actionName=action_name,
result={
'summary': 'Approval granted programmatically.',
'status': 'Approved'
},
token=approval_token
)

# Print the response for logging or debugging
print(response)

return {
'statusCode': 200,
'body': 'Approval result sent successfully.'
}

if action == 'reject':
# Provide rejection result
response = client.put_approval_result(
pipelineName=pipeline_name,
stageName=stage_name,
actionName=action_name,
result={
'summary': 'Rejection submitted programmatically.',
'status': 'Rejected'
},
token=approval_token
)

# Print the response for logging or debugging
print(response)

return {
'statusCode': 200,
'body': 'Rejection result sent successfully.'
}

return {
'statusCode': 200,
'body': json.dumps(f'Successfully triggered CodePipeline: {pipeline_name}'),
}
else:
return {
'statusCode': 400,
'body': json.dumps('Pipeline name not provided in URL parameters.'),
}


def get_approval_token(pipeline_name, stage_name, action_name):
# AWS CodePipeline client
client = boto3.client('codepipeline')

try:
# Get the current state of the pipeline
response = client.get_pipeline_state(name=pipeline_name)
print(response)
# Find the manual approval action in the response
for stage in response['stageStates']:
if stage['stageName'] == stage_name:
for action in stage['actionStates']:
if action['actionName'] == action_name:
# Extract and return the token for the manual approval action
return action['latestExecution']['token']
except Exception as e:
print(f"Error: {e}")

return None

def get_manual_approval_details(pipeline_name):
# AWS CodePipeline client
client = boto3.client('codepipeline')

try:
# Get details about the specified pipeline
response = client.get_pipeline(name=pipeline_name)
print(response)
manual_approval_details = response['pipeline']['stages'][1]
print(manual_approval_details)

stage_name = manual_approval_details['name']
action_name = manual_approval_details['actions'][0]['name']
return stage_name, action_name

except Exception as e:
print(f"Error: {e}")
return None

1_wkwdUSWcZRZ0jGpDI0_A5w (1).webp

Conclusion

In conclusion, by combining the power of AWS CodePipeline, Lambda functions, and SNS, you’ve successfully implemented a robust manual approval process in your deployment pipeline. This setup not only enhances the security and reliability of your deployment but also provides the flexibility to include human reviews where necessary.

Key Takeaways:

  • Seamless Manual Approval Setup: Easily incorporate manual approval steps into your CodePipeline for crucial decision-making points.
  • Lambda for Notification and Action: Leverage Lambda functions to send email notifications and take dynamic actions based on human decisions.
  • Efficient SNS Integration: Enhance communication with stakeholders through the use of SNS, ensuring timely and effective notifications.

Implement a manual approval process today using Lambda and SNS. Add crucial oversight to your automated deployments and empower your team with timely decision-making

  • AWS
  • DevOps

Continue Your Journey With…

DevOps as a Service

DevOps as a Service

Let us do the heavy lifting for you

Promotional banner
Promotional banner

Analyzing AWS IAM Users: Access Key and Password Age

Analyzing AWS IAM Users: Access Key and Password Age
  • DevOps
logo

Analyzing AWS IAM Users: Access Key and Password Age

Analyzing AWS IAM Users: Access Key and Password Age
  • AWS
  • DevOps
logo

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide
  • DevOps
logo

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide
  • AWS
  • DevOps
logo

Posts by Arya P B

Athena