How SAM CLI and AWS Lambda Powertools enable University Students to Start building solutions in less than 60 minutes
I am an Advanced Application Engineering Manager at Accenture in Australia and work hard advocating for Serverless Technology, accelerating teams new to building Serverless solutions on AWS. I design and build Serverless solutions using Event-Driven Architecture (EDA) and have been running a regular workshop called "Serverless Works!" internally at Accenture for the past two years. Another fun thing I do is run a 60-minute "Serverless Works!" session at the Accenture Technology Boot camps in Australia and New Zealand.
Accenture's technology boot camps are run throughout the year and bring together University students who are interested in technology careers and put them through a 4-day immersive boot camp experience with mentors from the Accenture MyWizard technology team to guide and support them. Students are put together in small project teams (4-6 students) and are assigned a project. Throughout the 4 days workshops are run on Design thinking, Project management and other technology-related topics to help them with their learning and to enable them to instantly apply what they learn in building their projects. To assist with the short timeframe, boot camps since 2021 have encouraged using AWS Cloud and Serverless technology. This is where I come in at the start of day 2 and do a "Serverless Works!" presentation to show them all how easy and fast it is to get started building with AWS Managed Services.
Most students who attend Accenture boot camps have no exposure to any cloud provider, so this workshop is really important to enable them to make a start. I introduce Serverless as a term and why it's such an important technology when wanting to build solutions quickly to deliver instant business value and provide instant scale meaning anything you build quickly is capable of running live with thousands of users with little to no effort or additional knowledge. Following this, I start demystifying the AWS Console - introducing what the cloud looks like and pointing out important services they will likely want to learn more about over the next four days - CloudFormation, CloudWatch, DynamoDB, API Gateway and Lambda. Next, I talk about the tools I use for my live coding demo to show them how easy it is to get started.
This is my list of getting-started tools and utilities for the boot camps:
An AWS Cloud Account
Leapp application from Leapp.cloud to secure access to their AWS account without needing to store Access Key and Secret Key on their computer unencrypted.
SAM CLI for deploying their application to the cloud
Visual Studio Code (or another code editor of their choice for editing files)
Python installed and working on their computer
AWS Lambda Powertools for Python to make writing AWS Lambda code faster and safer.
The above sounds like a daunting list, and by this time, many students are likely to wonder what it is I am talking about, and that's when I kick into a live coding demo and bare my developer soul to them. The solution I build is a simple REST API with AWS Lambda performing CRUD operations on DynamoDB - this is my target architecture, and I strive to get it finished in my workshop timeframe but do not always get there as I do talk a lot, and I get excited by Serverless!
It is amazing how fast it is to build a REST API these days with SAM CLI using the sample project wizard via sam init. With SAM CLI, I always start with the hello world sample application, which provides a nice project structure.
1. Execute: sam init
Within minutes a demo python project using the "Hello World" python template, and I can build and deploy it to the cloud.
2. Execute: sam build
I do this from an empty folder screen sharing my terminal so they can see first-hand how quick and easy it is to use the tools.
3. Execute: sam deploy -guided
While it deploys, I open the AWS Console and show the Cloudformation console and the stack creation, expanding the details to show the resources. I click the quick links to open the resources in their respective consoles to show how to find what is being built and show them in the console so they can build a mental model of a development workflow and visually start linking the consoles together, so they are less mysterious. Let's be honest - the AWS Console is an abstract, mysterious place that is not easy to get your head around when building a solution with so many different services.
Introducing AWS Lambda Powertools for Python
The last part of my live coding is refactoring the "Hello World" API lambda code using AWS Lambda Powertools for Python. I start by quickly importing AWS Lambda Powertools for Python and work through the following steps to refactor:
Import Logger and Tracer
create instances of these
Import APIGatewayRestResolver - While doing this, I explain how similar the utility is to python fast-API and node express libraries since students may be familiar with these from less serverless projects they have built.
Rework the Lambda handler to use the APIGatewatRestResolver class
Pretty quickly, we end up with code like this with the API route changed slightly to enable some dynamic responses based on input with a little fun thrown in.
The refactored code can be easily updated and re-deployed:
sam build
sam deploy
Once deployed, the demo now changes to show how the dynamic routes work, and I start to talk about how in a lot of cases, boot camp projects often involve Web or mobile app front-ends and dredge up everyone's dreaded API pain - Cross Origin Resource Sharing (CORS). So we add in Lambda Powertools CORS handling option (2 minor changes) and, at the same time, throw in how we can add in some AWS Lambda event logging to make debugging applications easier when they get building.
At this point in my demo, students have enough to get started with building and depending on the time I have left, I will keep going to add in DynamoDB and CRUD API methods or stop and open the floor for questions - the detail of building out a CRUD API is less important since by this time I have achieved the goal of my workshop. It is often far more important to engage with the students at this point and enable them to ask questions so I can address any specific concerns from the group
The final slide before I complete my workshop is a complete list of links for all the tools, demos, AWS online workshops, tutorials and sample code links. I do offer up a complete working boot camp demo repo on my GitHub with the complete CRUD API built and ready to deploy to help accelerate the project teams. I don't feel this is going too far because the students have never used AWS before, and this is the first time they are hearing about Serverless. The sample code provides a nice basis for them to get started in something more real, and they can achieve instant success which is important for a 4-day immersive experience.
Why Choose SAM CLI?
I choose SAM CLI because I find this an easy and approachable tool which has a nice wizard-style approach to getting started and makes building and deploying straightforward to get going. I also provide links to AWS Workshops and the first workshop in the list is Create A Hello World Lambda Function (using SAM CLI) so it ties in well and reinforces my live coding demo!
Why AWS Lambda Powertools?
This is simple - because every Serverless project that writes code for Lambda should use this library. It provides AWS Serverless best practice principles right out of the box and with very little effort. I encourage every serverless team I work with to use AWS Lambda Powertools, and I also strongly push Python as the language they should be building with. This utility library does enable Serverless teams to run faster by providing standard approaches to Logging, Tracing, Efficient Metrics, Resolvers for APIs (all types) and Stream batch handlers which make writing SQS handler functions safer and more robust - so many AWS Well-Architected principles are embodied in AWS Lambda Powertools. It simply makes coding faster.
Seeing project teams embracing Serverless technology with a single workshop presentation is refreshing to experience. I love presenting my Serverless Works! Boot Camp edition for University students attending Accenture's Technology boot camps. I am also addicted to writing code in front of developers to showcase new techniques or ways of building. Sharing my knowledge and love of Serverless building and doing it immediately with instant effect is very satisfying.