How to Deploy Your Lambda Functions with CloudFormation
Tags: lamda, aws, cloudformation
Published: 2022-08-31 07:38:40

---
title: How to Deploy Your Lambda Functions with CloudFormation
published: true
description: AWS Lambda is a powerful tool for developing serverless applications and on-demand workflows. However, this power comes at a cost in terms of flexibility and ease of deployment, as the manual deployment process that AWS Lambda recommends can be error-prone and hard to scale. 
tags: #lamda #aws #cloudformation
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
---
*by Matt Billock*

AWS Lambda is a powerful tool for developing serverless applications and on-demand workflows. However, this power comes at a cost in terms of flexibility and ease of deployment, as the manual deployment process that AWS Lambda recommends can be error-prone and hard to scale. 

CloudFormation revolutionizes this process, [replacing copied zip files] (https://aws.amazon.com/blogs/infrastructure-and-automation/deploying-aws-lambda-functions-using-aws-cloudformation-the-portable-way/) with dependable and repeatable template-based deployment schemes. With CloudFormation, your Lambda functions will be easier to maintain, easier for your developers to understand, and easier to scale as your application grows.

##Reviewing AWS Lambda Deployments
AWS Lambda function deployments are based around file handling-namely, by zipping your code into an archive and uploading the file to AWS. At its core, all AWS Lambda functions follow this pattern:

-Create a zip file.
-Upload to an S3 bucket.
-Set the function to active.

This takes place whether you’re manually deploying the code, have outsourced your deployments to a tool, or are following any protocol in-between.

Once the file is received, AWS unzips your code into the appropriate folder structure, making it available to run when the Lambda container is spun up. This approach is a key point to remember as we discuss Lambda deployments and also exposes one of the first holes in the manual deployment process—AWS Lambda functions have an unstated structure that you need to follow. 

Simply put, you do not want to right-click on a file and create an archive; otherwise, you’ll encounter an error when you try to run your deployed Lambda code. The following screenshots illustrate this issue:
![run your deployed Lambda code](https://i.ibb.co/5srs9M1/image3-1-1024x796.jpg)*Figure 1: Do not zip the folder using this method*

If you examine the zip files produced by the above method, you’ll find that their root level consists of your code folder:
![](https://i.ibb.co/THxSRRn/image5.jpg)*Figure 2: This zip file will not be parsable by AWS Lambda*

The issue this introduces is specifically related to how AWS Lambda deploys the code—namely, it simply unzips the provided code archive to an executable folder, then routes invocation requests to the application code found in that folder. When you provide a zip archive with a folder at the root level, instead of the application code itself, AWS Lambda has no idea what to do and throws errors.

Enjoy the article? **[Continue reading] (https://developernation.net/blog/how-to-deploy-your-lambda-functions-with-cloudformation?utm_medium=some&utm_source=dev_to&utm_campaign=devto_continue_reading_deploylamda)**