How To Deploy Serverless SAM Using Code Pipeline (5 Min) | Using AWS Code Build & Code Commit

Gokce DB
18 Dec 202205:39

Summary

TLDRABI from gokjdb guides viewers through deploying a serverless AWS SAM application using AWS CodeBuild and AWS CodePipeline. The tutorial covers creating a repository, setting up a serverless project with the Python runtime, configuring and deploying the application, and verifying deployment through an API Gateway URL. It also explains creating a buildspec.yml file, setting permissions for the service role, and automating the deployment process with a pipeline that responds to code changes, culminating in a demonstration of updating the application and redeploying.

Takeaways

  • ๐Ÿ“ Start by creating a repository in AWS Code Commit and cloning it locally.
  • ๐Ÿ› ๏ธ Use the AWS SAM (Serverless Application Model) CLI to create a new serverless project with Python as the runtime.
  • ๐Ÿ”„ Choose 'Create from existing sources' and allow time for project files to be generated.
  • โš™๏ธ Configure the project using the 'hello world' template and run it to ensure it works.
  • ๐Ÿš€ Execute 'sam build' and 'sam deploy --guided' to deploy the application and follow the prompts for configuration.
  • ๐Ÿ”— After deployment, check the logs for the API Gateway endpoint URL and verify the application by accessing it.
  • ๐Ÿ“„ Create a 'buildspec.yml' file necessary for deploying the application with AWS CodeDeploy.
  • ๐Ÿ”„ Commit and push all project files to the Code Commit repository.
  • ๐Ÿ—๏ธ Set up a build project in AWS CodeBuild, specifying the source, branch, and operating system.
  • ๐Ÿ‘ฎโ€โ™‚๏ธ Add necessary permissions to the service role for access to AWS services like S3, CloudWatch, API Gateway, CloudFormation, and Lambda.
  • ๐Ÿ”„ Initiate the build process and monitor the logs for success or errors.
  • ๐Ÿ”„ Create a pipeline in AWS CodePipeline, linking it to the source and build projects.
  • ๐Ÿ”„ Make changes to the application, commit, and push to trigger the pipeline's automated build and deployment process.
  • ๐Ÿ”„ Monitor the pipeline and build logs to confirm successful deployment of changes.

Q & A

  • What is the main topic of the video?

    -The main topic of the video is how to deploy a serverless AWS SAM (Serverless Application Model) application using AWS CodeBuild and AWS CodePipeline.

  • What is the first step mentioned in the script for deploying a serverless application?

    -The first step is to navigate to the CodeCommit service, create a new repository, and clone it to the local machine using 'git clone'.

  • Which tool is used to create a new AWS serverless project?

    -The tool used to create a new AWS serverless project is the AWS SAM CLI (Command Line Interface).

  • What runtime is chosen for the serverless project in the video?

    -Python is chosen as the runtime for the serverless project.

  • What template is selected in the configuration for the SAM application?

    -The 'Hello World' template is selected as the input for the SAM application configuration.

  • What command is used to build the SAM application in the terminal?

    -The command used to build the SAM application is 'sam build'.

  • What does 'Sam deploy --guided' do in the script?

    -'Sam deploy --guided' is used to follow the prompts and set the configuration for the SAM deployment.

  • What file is created for deploying the application using CodeDeploy?

    -A 'buildspec.yml' file is created, which is needed when deploying the application using CodeDeploy.

  • What service role is mentioned in the script, and why is it important?

    -The service role mentioned is important because it needs to have permissions to access AWS services like S3, CloudWatch, API Gateway, CloudFormation, and Lambda for the deployment process.

  • What is the purpose of creating an AWS CodePipeline?

    -The purpose of creating an AWS CodePipeline is to automate the deployment process by integrating source control, build, and deployment stages.

  • How does the video script demonstrate updating the application?

    -The script demonstrates updating the application by editing the 'app.py' file, changing the output message, committing the change, and pushing it to the remote master branch to trigger a new pipeline execution.

Outlines

00:00

๐Ÿš€ Deploying Serverless SAM Application

This paragraph outlines the process of deploying a serverless AWS SAM application using AWS CodeBuild and AWS CodePipeline. It begins with creating a repository in the Code Commit service, cloning it, and setting up a new AWS serverless project with Python as the runtime. The video demonstrates running the project, building it with SAM, and deploying it with guided prompts, resulting in an API Gateway endpoint. The paragraph concludes with the successful deployment, as indicated by a 'hello world' message, and the creation of a buildspec.yml file for future CodeDeploy usage.

05:00

๐Ÿ”„ Automating Deployment with CodePipeline

In this paragraph, the focus shifts to automating the deployment process using AWS CodePipeline. It starts with committing and pushing project files to the Code Commit repository, followed by creating a build project in AWS CodeBuild, specifying the source, branch, and operating system. The paragraph details the setup of permissions for the service role to access necessary AWS services. The build process is initiated, and the viewer is guided to monitor the build logs for success. The paragraph also covers the creation of a CodePipeline, configuring its stages, and observing the pipeline's automatic execution upon code changes. The summary ends with the viewer being prompted to check the updated API endpoint after a change is made to the app.py file, signifying a successful automated deployment cycle.

Mindmap

Keywords

๐Ÿ’กServerless

Serverless refers to a cloud computing execution model where the cloud provider dynamically manages the allocation and provisioning of servers. In the video, deploying a serverless application means the user does not need to manage servers, as AWS handles this, which simplifies the deployment and scaling of applications.

๐Ÿ’กAWS CodeBuild

AWS CodeBuild is a fully managed build service provided by Amazon Web Services. It compiles source code, runs tests, and produces ready-to-deploy software packages. In the video, it is used to automate the build process of the serverless application, ensuring that the application is built correctly before deployment.

๐Ÿ’กAWS CodePipeline

AWS CodePipeline is a continuous integration and continuous delivery service that helps developers to automate their release pipelines. The video demonstrates the creation of a pipeline that automates the deployment process of the serverless application, ensuring that changes are automatically built and deployed.

๐Ÿ’กCode Commit

AWS CodeCommit is a source control service that hosts private Git repositories. In the video, the presenter uses Code Commit to create a new repository for the project, which is then used to store and manage the application's source code.

๐Ÿ’กGit Clone

Git Clone is a command in Git, a version control system, used to create a local copy of a repository. The script describes cloning the repository to the local machine, which is the first step in setting up the development environment for the serverless application.

๐Ÿ’กSAM (Serverless Application Model)

The Serverless Application Model (SAM) is an open-source framework provided by AWS for building serverless applications. The script mentions using SAM to create a new AWS serverless project, which simplifies the process of defining and deploying serverless applications.

๐Ÿ’กAPI Gateway

Amazon API Gateway is a fully managed service that makes it easy to create, publish, maintain, monitor, and secure APIs at any scale. In the video, the deployment of the serverless application results in an API Gateway endpoint, which is used to access the deployed application.

๐Ÿ’กBuild Spec

A build specification file, often named 'buildspec.yml', contains instructions for AWS CodeBuild to build the source code. The video script mentions creating a 'buildspec.eml' file, which is a configuration file for the build process, specifying how the application should be built.

๐Ÿ’กIAM Service Role

AWS Identity and Access Management (IAM) service roles are AWS identities that you can use to assign permissions to AWS services. In the video, the presenter navigates to the IAM service to add permissions to a service role, which is necessary for AWS CodeBuild to access other AWS services on behalf of the user.

๐Ÿ’กS3

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. The script mentions attaching policies to the IAM service role to grant full access to S3, which is likely used to store artifacts or logs during the build and deployment process.

๐Ÿ’กLambda

AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. The video script does not explicitly mention Lambda, but as part of a serverless application, it is implied that Lambda functions could be part of the application being deployed, handling the backend logic triggered by the API Gateway.

Highlights

Introduction to deploying a serverless SAM application using AWS CodeBuild and AWS CodePipeline.

Navigating to the Code Commit service and creating a new repository.

Cloning the repository to a local machine using Git.

Using the AWS SAM CLI to create a new serverless project with Python runtime.

Creating project files from existing sources and configuring the SAM application.

Running the SAM application and verifying the 'Hello World' message in the console output.

Building and deploying the SAM application with guided configuration.

Viewing the API Gateway endpoint URL in the deployment logs after successful deployment.

Creating a buildspec.yml file for deploying the application using AWS CodeDeploy.

Committing and pushing project files to the Code Commit repository.

Confirming the presence of all files in the repository and creating a build project in AWS CodeBuild.

Specifying the source, branch, operating system, and runtime for the build project.

Configuring permissions for the service role to access necessary AWS services.

Starting the build process and monitoring the build logs for success.

Creating an AWS CodePipeline for automated deployment.

Setting up the source provider and build provider in the pipeline configuration.

Skipping the deploy stage and executing the pipeline to initiate the build step.

Editing the app.py file to update the output message and committing the changes.

Observing the pipeline's automatic response to code changes and initiating a new build.

Successfully deploying the updated application and verifying the new message via the API endpoint.

Encouragement to like, subscribe, and enable notifications for future content.

Transcripts

play00:00

hi guys this is ABI from gokjdb in this

play00:04

video you're going to learn how to

play00:06

deploy a serverless Sam application

play00:09

using AWS code build and AWS code

play00:13

pipeline

play00:15

let's start by navigating to the code

play00:17

commit service then click on create

play00:20

repository and give it a name

play00:23

hit create then clone this repository to

play00:27

your local machine using git clone

play00:31

next I'm going to use pie charm to

play00:34

create a new AWS serverless project

play00:37

inside my Repository

play00:40

choose python for runtime then hit

play00:43

create from existing sources

play00:46

give it a few minutes for the project

play00:48

files to get created then click on the

play00:52

configuration drop down and hit edit

play00:55

choose the hello world template as your

play00:58

input then hit run

play01:01

looks like our Sam application is

play01:04

working as expected since we see the

play01:07

hello world message in the console

play01:09

output

play01:10

next click on the terminal tab then type

play01:14

Sam build followed by Sam deploy hyphen

play01:18

hyphen guided

play01:20

follow the prompts to set the

play01:23

configuration for Sam deploy then wait

play01:26

for the deployment to complete

play01:29

after the application is deployed you

play01:32

should see an API Gateway endpoint URL

play01:35

in the deployment logs click on this URL

play01:39

and you should see a hello world message

play01:41

which means our application was

play01:44

successfully deployed

play01:46

next I'm going to create a build spec

play01:49

dot EML file which we will need when we

play01:52

deploy this application using Code

play01:55

deploy

play01:56

now let's commit and push all our

play01:59

project files to our code commit

play02:02

Repository

play02:03

let's head back to the code commit

play02:06

service and confirm that we see all

play02:09

these files in our my Sam repo

play02:12

next click on build projects under code

play02:16

build then click on create build project

play02:19

give your build project a name then

play02:22

specify my Sam repo as your code commit

play02:26

source

play02:27

select the master Branch then choose

play02:31

Amazon Linux 2 as the operating system

play02:34

for the managed image

play02:37

select standard for runtime then pick an

play02:41

image

play02:42

I'm going to copy the name of the new

play02:45

service role because we'll need it to

play02:47

add more permissions later

play02:50

for build specify build spec.aml then

play02:54

hit create

play02:56

next let's navigate to the IAM service

play02:59

then find the service role that we just

play03:02

copied go inside this role then click on

play03:06

ADD permissions then attach policies I'm

play03:11

going to give this role full access to

play03:13

IAM S3 Cloud watch API Gateway cloud

play03:18

formation and Lambda

play03:21

next click on start build then hit tail

play03:25

logs give it a few minutes and if there

play03:28

are no errors in the build logs you

play03:31

should see the succeeded message

play03:34

now let's create a code pipeline click

play03:37

on pipelines then hit create

play03:41

give your pipeline a name hit next then

play03:44

choose AWS code commit as your Source

play03:48

provider

play03:49

select your repository and the master

play03:52

Branch then click on next choose AWS

play03:56

code build as the build provider then

play04:00

select the my Sam build project and hit

play04:03

next

play04:04

I'm going to skip the deploy stage

play04:07

because we are running Sam deploy in the

play04:10

build step

play04:12

hit create Pipeline and your pipeline

play04:15

should start getting executed

play04:16

automatically

play04:18

give it a few minutes for your source

play04:20

code to check out then the pipeline will

play04:23

automatically kick off the code build

play04:25

step

play04:26

to look at your build logs click on

play04:29

details in the build step then hit tail

play04:33

logs

play04:34

wait for few minutes for the build to

play04:37

complete and if there are no errors you

play04:40

should see the succeeded message

play04:42

next let's edit our app.py file and

play04:47

change the output message to hello world

play04:50

dash version 2. let's commit and push

play04:54

this change to our remote Master Branch

play04:57

let's head back to the code pipeline

play05:00

window to see if our code pipeline

play05:03

automatically picks up this change and

play05:05

starts a new execution looks like a new

play05:09

build is now in progress let's click on

play05:12

details and tell the build logs give it

play05:16

a few minutes for the build to complete

play05:18

then grab the API endpoint URL

play05:22

looks like our change was successfully

play05:24

deployed there you have it make sure you

play05:27

like subscribe and turn on the

play05:30

notification Bell until next time

Rate This
โ˜…
โ˜…
โ˜…
โ˜…
โ˜…

5.0 / 5 (0 votes)

Related Tags
ServerlessAWSSAMCodeBuildCodePipelineDeploymentAPI GatewayCloudFormationLambdaDevOpsPython