Bitbucket pipeline for deploying Lambda using serverless

In this article, we are talking about AWS lambda functions deployment with Bitbucket Pipelines.

Serverless computing has gained popularity in the last few years primarily because it supports both ease of development and high scalability. Serverless functions are stateless, event-driven, and highly scalable, and they don’t have any dependencies on the underlying infrastructure. AWS Lambda is the leading example of a serverless computing platform.

Prerequisite:

  • A lambda function project built using the Serverless Framework ( refer to this article)
  • AWS access key & AWS secret access key with enough rights to deploy Lambda function
  • S3 bucket is needed to store artefacts (release build).

We need to configure repository variables

Repository settings -> Repository variables

repository variables.png

We will be using defining the location of the release files, access key id and secret key ID.

In our previous article, we had already discussed how to build a .Net6.0 application using the bitbucket pipeline

As we had already created the lambda and build using the bitbucket pipeline. Now we need to add a serverless template file in the actual project to define the configuration of Lambda.

Changing the Existing bitbucket yml to copy the release files to the s3 bucket, So that build artefacts will persist. Created beta environment.

final bitbucket yml.png

In the above yml file, the lambda function is build and copies the release files so the S3 bucket. Finally creates a BETA environment and deploys the lambda. By doing this configuration for deployment is completed. Now We need to configure the serverless template file to configure the lambda.

Note: When we create a yml file make sure it should add to a projects item group

itemgroup.png

Serverless yml file

We need to define the yml file for defining the configuration of lambda and save the file at the project level

project level yml.png

Serverless yml template

serverlesstemplate.png

In the above template, we define the name of the function, runtime and time-out configuration and defining what are the resources lambda can access to.

finally commit and push the changes.

Once pipeline building is completed we can see the build published files are stored in the S3 bucket

pipeline build to s3.png

s3bucketfiles.png

Finally, after the build is finished We can see in the bitbucket pipeline had successfully deployed and a New lambda is created.

finished build.png

Final Lambda.png

final API.png