Learn how to ๐ฐ๐ฟ๐ฒ๐ฎ๐๐ฒ, ๐ฑ๐ฒ๐ฝ๐น๐ผ๐ & ๐บ๐ผ๐ป๐ถ๐๐ผ๐ฟ your AWS Lambda functions from your local terminal via the AWS CLI ๐งต โ
๐ข๐๐ฒ๐ฟ๐๐ถ๐ฒ๐ ๐งต
โข Installing & setting up the AWS CLI
โข Setting up an Execution Role
โข Packaging your Function's Code
โข Creating a Function
โข Invoking Functions
โข Deploying Code Updates
โข Monitoring Executions
โข Updating Configurations
โข Deleting Functions
๐๐ป๐๐ฟ๐ผ๐ฑ๐๐ฐ๐๐ถ๐ผ๐ป
At AWS, everything is an API. Even if you're using the console interface, the browser only translates your clicks to calls to the AWS API.
That's why you can easily automate everything around Lambda from your local terminal.
This includes the ๐ฐ๐ฟ๐ฒ๐ฎ๐๐ถ๐ผ๐ป ๐ผ๐ณ ๐ฎ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป, attaching necessary ๐ฝ๐ฒ๐ฟ๐บ๐ถ๐๐๐ถ๐ผ๐ป๐ ๐๐ถ๐ฎ ๐ฎ๐ป ๐ฒ๐ ๐ฒ๐ฐ๐๐๐ถ๐ผ๐ป ๐ฟ๐ผ๐น๐ฒ, ๐ฝ๐ฎ๐ฐ๐ธ๐ฎ๐ด๐ถ๐ป๐ด and ๐ฑ๐ฒ๐ฝ๐น๐ผ๐๐ถ๐ป๐ด, as well as monitoring and debugging. There's no reason to leave your terminal at all.
When using macOS, you can use ๐ต๐ผ๐บ๐ฒ๐ฏ๐ฟ๐ฒ๐ via ๐ฏ๐ฟ๐ฒ๐ ๐ถ๐ป๐๐๐ฎ๐น๐น ๐ฎ๐๐๐ฐ๐น๐ถ to get the latest version.
For Linux and Windows, there's a similar process.
You need to be authenticated and authorized to access your account via the AWS CLI.
This requires you to have an Access Key ID and Secret Access Key.
Let's head over to your user's security credentials settings so we can create a pair of those.
You can now run ๐ฎ๐๐ ๐ฐ๐ผ๐ป๐ณ๐ถ๐ด๐๐ฟ๐ฒ to set up your key pair locally.
If you've done everything correctly, you should be able to get a few details of your account and user by running ๐ฎ๐๐ ๐๐๐ ๐ด๐ฒ๐-๐ฐ๐ฎ๐น๐น๐ฒ๐ฟ-๐ถ๐ฑ๐ฒ๐ป๐๐ถ๐๐.
The AWS-CLI is great, but it's often also not very intuitive as it's packed with a lot of commands. Wouldn't it be great to have auto-completion and a lot more documentation right in the terminal?
Each Lambda function needs an attached role at AWS Identity and Access Management (IAM).
This role is automatically assumed by the function when its executed.
Let's adapt our function a little bit and repackage it
Then we'll deploy it via ๐๐ฝ๐ฑ๐ฎ๐๐ฒ-๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป-๐ฐ๐ผ๐ฑ๐ฒ.
We can also access the logs via our terminal via CloudWatch Logs for Humans.
It's simple to install either via pip (๐ฝ๐ถ๐ฝ ๐ถ๐ป๐๐๐ฎ๐น๐น ๐ฎ๐๐๐น๐ผ๐ด๐) or homebrew (๐ฏ๐ฟ๐ฒ๐ ๐ถ๐ป๐๐๐ฎ๐น๐น ๐ฎ๐๐๐น๐ผ๐ด๐)
When we run ๐ฎ๐๐๐น๐ผ๐ด๐ ๐ด๐ฟ๐ผ๐๐ฝ๐ --๐ฎ๐๐-๐ฟ๐ฒ๐ด๐ถ๐ผ๐ป ๐๐-๐ฒ๐ฎ๐๐-๐ญ there are no logs yet for our function
Because our execution role doesn't include the necessary CloudWatch permissions
Let's fix this by attaching the AWS-managed AWSLambdaBasicExecutionRole policy
Let's check the logs via ๐ฎ๐๐๐น๐ผ๐ด๐ ๐ด๐ฒ๐ /๐ฎ๐๐/๐น๐ฎ๐บ๐ฏ๐ฑ๐ฎ/๐บ๐๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป --๐๐ฎ๐๐ฐ๐ต --๐ฎ๐๐-๐ฟ๐ฒ๐ด๐ถ๐ผ๐ป ๐๐-๐ฒ๐ฎ๐๐-๐ญ
As we've used --๐๐ฎ๐๐ฐ๐ต the log stream will stay open.
Every output from the following invocations will be streamed to your terminal.
If you've enjoyed this thread, we're happy about a โป๏ธ or โฅ๏ธ of the initial post so others can see it too!
If you're interested in more, sign up for our newsletter and get a ๐ณ๐ฟ๐ฒ๐ฒ ๐๐ฎ๐บ๐ฝ๐น๐ฒ ๐ฐ๐ต๐ฎ๐ฝ๐๐ฒ๐ฟ of our book straight into your inbox ๐จ โ
AWS offers a wide range of ๐ฐ๐ผ๐บ๐ฝ๐๐๐ฒ ๐๐ฒ๐ฟ๐๐ถ๐ฐ๐ฒ๐ ๐ค
From well-known services like ๐๐๐ฎ to rather exotic ones like ๐ช๐ฎ๐๐ฒ๐น๐ฒ๐ป๐ด๐๐ต ๐งต โ
๐๐บ๐ฎ๐๐ผ๐ป ๐๐๐ฎ
One of the most mature services by AWS launched back in 2006.
With EC2 you can rent virtual machines to run basically any workload, as it offers a wide range of hardware, including memory and compute-optimized instances.
๐๐ช๐ฆ ๐๐ฎ๐ฟ๐ด๐ฎ๐๐ฒ
Amazon ECS is a highly scalable and fast container management service. Simply run, stop & manage containers.
AWS Fargate is the serverless compute engine that's underneath ECS and that is used to execute the workloads.
You don't want to compile your apps locally and ship them to prod with a team of any size. Maybe there are a lot of different steps and you want to execute them reliably and in a way that's easily traceable.
It abstracts away all the tedious work you'd had with Terraform or CloudFormation when building Lambda-powered apps ๐๏ธ
A not-that-small thread about ๐ฎ๐น๐น ๐๐ผ๐ ๐ป๐ฒ๐ฒ๐ฑ ๐๐ผ ๐ธ๐ป๐ผ๐ to get started ๐งตโ
๐๐ป๐๐ฟ๐ผ๐ฑ๐๐ฐ๐๐ถ๐ผ๐ป
Creating the needed infrastructure for a simple Lambda-powered service exposed to the internet is not a trivial task, even though this is a widespread use case.
What if thereโd be a framework that solely focuses on everything around Lambda?
And thatโs exactly what Serverless Framework does.
And it does it beautifully!
It abstracts away a lot of the boilerplate configuration you need for Lambda, API Gateway, and other native integrations with other services.
In the past year, I did a lot of ๐๐ช๐ฆ ๐๐ต๐ฟ๐ฒ๐ฎ๐ฑ๐ ๐งต
I've revisited my timeline & cherry-picked the ๐ฏ๐ฒ๐๐ ๐ฑ ๐๐ต๐ฟ๐ฒ๐ฎ๐ฑ๐ that will help you to ๐ท๐๐บ๐ฝ-๐๐๐ฎ๐ฟ๐ ๐๐ผ๐๐ฟ ๐ฐ๐น๐ผ๐๐ฑ ๐ท๐ผ๐๐ฟ๐ป๐ฒ๐ ๐ค