In this article we are going to cover Creating Jenkins Pipeline for AWS SAM Application Deployment | Deploy AWS SAM Applications with Jenkins CI/CD Pipeline.
In modern DevOps workflows, automation is key to efficient and reliable deployments. AWS Serverless Application Model (AWS SAM) streamlines the development and deployment of serverless applications, while Jenkins provides a robust CI/CD automation framework.
This article guides you through building a Jenkins pipeline for AWS SAM, covering setup, pipeline configuration, and deployment stages. By the end, you’ll have a fully automated pipeline that builds, tests, and deploys serverless applications seamlessly to AWS Lambda.
Table of Contents
Prerequisites
Before setting up a Jenkins pipeline for AWS SAM deployment, ensure you have the following:
- AWS Account – An active AWS account with permissions to deploy AWS Lambda and related resources.
- Jenkins Installed – A running Jenkins server with access to install necessary plugins.
- AWS SAM CLI – Installed to build and package serverless applications.
- GitHub Repository – A source code repository to store your AWS SAM application.
- Docker – Docker should be installed.
Below is the Workflow Diagram:

Step #1:Initialize a New AWS SAM Project using GitHub
Create a Repository in GitHub:

Set up a fresh AWS SAM project in the repository directory:
sam init
Select the following options:

go to the repository by using below command:
cd sam-app
You can see new files in the repository:

Step #2:Commit and Push Changes to GitHub
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/username/repo.git
git push -u origin main

Step #3:Allow Jenkins Users to Access the Docker Socket
Use below commands to allow Jenkins users to access the docker socket:
sudo usermod -aG docker jenkins
After that restart jenkins:
sudo systemctl restart jenkins
Without the above configurations, Jenkins will not be able to access Docker Hub.
Step #4:Download Plugins in Jenkins for AWS SAM Application
Download the following plugins Manage plugins > Plugins > Available Plugins:
- Pipeline Stage View
- AWS Credentials
- AWS SAM
- Pipeline: AWS Steps
- Docker Pipeline





Step #5:Add AWS IAM Credentials in Jenkins
Add AWS Credentials by Manage Jenkins > Credentials > global > Add Credentials
Select AWS Credentials in Kind and then add ID, Access Key ID and Secret Access Key

Step #5:Jenkins CI/CD for AWS SAM Application using Jenkins
Jenkins Pipeline Code to deploy AWS SAM application
pipeline {
agent {
docker {
image 'public.ecr.aws/sam/build-python3.13' // Uses AWS-provided SAM CLI image
args '-u root' // Run as root inside the container
}
}
environment {
AWS_REGION = 'ap-south-1'
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', url: 'https://github.com/harish981/aws-sam-jenkins.git'
}
}
stage('Install AWS SAM CLI') {
steps {
sh '''
sam --version # Check if SAM CLI is already installed
'''
}
}
stage('Build SAM Application') {
steps {
sh '''
sam build
'''
}
}
stage('Deploy to AWS') {
steps {
withAWS(credentials: 'aws-credentials-id', region: "${AWS_REGION}") {
sh '''
sam deploy --stack-name my-sam-app --resolve-s3 --capabilities CAPABILITY_IAM --no-confirm-changeset
'''
}
}
}
}
post {
failure {
echo 'Deployment failed! ❌'
}
success {
echo 'Deployment successful! ✅'
}
}
}
Use the above Pipeline code in Jenkins Configuration and replace the “aws-credentials-id” with your credentials id which you gave in the AWS Credentials.
After Build you’ll get the output as shown below:

Access the URL in Console Output:


You can also review the deployment details, including the resources created as part of the my-sam-app and aws-sam-cli-managed-default stacks in CloudFormation:

Remove the resources (two stacks in CloudFormation) if they are no longer needed.
Conclusion:
Setting up a Jenkins pipeline for AWS SAM makes deploying serverless applications easier and more efficient. By automating the process, you ensure consistent and reliable deployments. With Jenkins and AWS SAM working together, managing serverless applications becomes simple and streamlined.
Related Articles:
Deploy AWS SAM Applications with GitLab CI/CD Pipeline
Reference: