Tobias Schmidt Profile picture
Feb 12 โ€ข 19 tweets โ€ข 6 min read
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.

docs.aws.amazon.com/cli/latest/useโ€ฆ
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.

us-east-1.console.aws.amazon.com/iam/home?regioโ€ฆ
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?

That's exactly what aws-shell does.

github.com/awslabs/aws-shโ€ฆ
๐—ฆ๐—ฒ๐˜๐˜๐—ถ๐—ป๐—ด ๐˜‚๐—ฝ ๐—ฎ๐—ป ๐—˜๐˜…๐—ฒ๐—ฐ๐˜‚๐˜๐—ถ๐—ผ๐—ป ๐—ฅ๐—ผ๐—น๐—ฒ

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 create a minimal Node.js function handler. It will only return the function's name and the memory configuration.

Afterward, we can use the Lambda CLI for the first time via aws lambda create-function.
๐—œ๐—ป๐˜ƒ๐—ผ๐—ธ๐—ถ๐—ป๐—ด ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€

Now that we've created our function, let's see if we can invoke it via the CLI.

The log results are Base64 encoded, but we can decode them on-the-fly via ๐—ท๐—พ.
๐——๐—ฒ๐—ฝ๐—น๐—ผ๐˜†๐—ถ๐—ป๐—ด ๐—–๐—ผ๐—ฑ๐—ฒ ๐—จ๐—ฝ๐—ฑ๐—ฎ๐˜๐—ฒ๐˜€

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 (๐—ฏ๐—ฟ๐—ฒ๐˜„ ๐—ถ๐—ป๐˜€๐˜๐—ฎ๐—น๐—น ๐—ฎ๐˜„๐˜€๐—น๐—ผ๐—ด๐˜€)

github.com/jorgebastida/aโ€ฆ
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.
๐—จ๐—ฝ๐—ฑ๐—ฎ๐˜๐—ถ๐—ป๐—ด ๐—–๐—ผ๐—ป๐—ณ๐—ถ๐—ด๐˜‚๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€

Lastly, let's adapt our function's configuration. Maybe we want to have more memory and a longer timeout.
๐——๐—ฒ๐—น๐—ฒ๐˜๐—ถ๐—ป๐—ด ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€

Let's finish our journey with the Lambda CLI by cleaning up our function and execution role.

That's it. We've gone through the full cycle and we've cleaned up our resources afterward.
Read the full article on @hashnode ๐Ÿ“š

blog.awsfundamentals.com/mastering-the-โ€ฆ
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 ๐Ÿ“จ โ†“

awsfundamentals.com

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Tobias Schmidt

Tobias Schmidt Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @tpschmidt_

Feb 9
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.
Read 13 tweets
Sep 8, 2022
๐—”๐—ช๐—ฆ ๐—–๐—ผ๐—ฑ๐—ฒ๐—•๐˜‚๐—ถ๐—น๐—ฑ & ๐—–๐—ผ๐—ฑ๐—ฒ๐—ฃ๐—ถ๐—ฝ๐—ฒ๐—น๐—ถ๐—ป๐—ฒ

Reliable, Secure & Serverless Continuous Integration and Delivery ๐Ÿ—

๐— ๐—ฒ๐—ด๐—ฎ ๐˜๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ about the Pros, Cons & everything you need to know ๐Ÿงต
๐—œ๐—ป๐˜๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐Ÿ‘‹

AWS CodeBuild & CodePipeline is a fully-managed service to build, package & deploy your apps and infrastructure.

Focus on developing your application & worry less about efforts & operations to ship it to your customers!
๐—œ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ ๐—ผ๐—ณ ๐—–๐—œ/๐—–๐—— โญ๏ธ

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.
Read 33 tweets
Sep 1, 2022
ฮป๏ธ ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ๐—น๐—ฒ๐˜€๐˜€ ๐—™๐—ฟ๐—ฎ๐—บ๐—ฒ๐˜„๐—ผ๐—ฟ๐—ธ ๐Ÿญ๐˜…๐Ÿญ โšก

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.
Read 19 tweets
Aug 25, 2022
In the past year, I did a lot of ๐—”๐—ช๐—ฆ ๐˜๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐˜€ ๐Ÿงต

I've revisited my timeline & cherry-picked the ๐—ฏ๐—ฒ๐˜€๐˜ ๐Ÿฑ ๐˜๐—ต๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐˜€ that will help you to ๐—ท๐˜‚๐—บ๐—ฝ-๐˜€๐˜๐—ฎ๐—ฟ๐˜ ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ฐ๐—น๐—ผ๐˜‚๐—ฑ ๐—ท๐—ผ๐˜‚๐—ฟ๐—ป๐—ฒ๐˜† ๐ŸŒค

โ†“ ๐Ÿ™
Free tutorials for AWS Core Services.

Important reminders about keeping an eye on costs & helping you to sleep better when working with AWS.

Read 6 tweets
Aug 8, 2022
In every project I have worked on as a freelancer, AWS has been heavily used

So I can assure you: even small cloud expertise is a ๐—ต๐—ถ๐—ด๐—ต-๐˜ƒ๐—ฎ๐—น๐˜‚๐—ฒ ๐˜€๐—ธ๐—ถ๐—น๐—น โšก๏ธ

If you're struggling with how to begin, read on to learn about the core services & free tutorials ๐Ÿงต๐Ÿ‘‡
1๏ธโƒฃ AWS offers great free tutorials on its own training site, ranging from beginner to expert levels.

You only need an Amazon account to get yourself started.

aws.training/LearningLibrary
2๏ธโƒฃ Amazon Elastic Compute Cloud (๐—˜๐—–๐Ÿฎ)

EC2 provides computing capacity for all kinds of areas. Launch virtual instances and services in the blink of an eye & run your applications.

With AWS' free tier, you can run a t2 or t3 micro instance for free.

explore.skillbuilder.aws/learn/course/eโ€ฆ
Read 12 tweets
Aug 3, 2022
๐Ÿ•ต ๐—š๐—ผ๐—ผ๐—ด๐—น๐—ฒ ๐—ฆ๐—ธ๐—ถ๐—น๐—น๐˜€ > ๐˜’๐˜ฏ๐˜ฐ๐˜ธ๐˜ญ๐˜ฆ๐˜ฅ๐˜จ๐˜ฆ ๐Ÿ“š ๏ธ

You can't know everything & most of your problems have been already solved by someone else.

A small set of ๐—š๐—ผ๐—ผ๐—ด๐—น๐—ฒ ๐˜€๐˜‚๐—ฝ๐—ฒ๐—ฟ๐—ฝ๐—ผ๐˜„๐—ฒ๐—ฟ๐˜€ to help you find anything ๐Ÿงต โ†“
๐—˜๐˜…๐—ฐ๐—น๐˜‚๐—ฑ๐—ฒ ๐˜„๐—ผ๐—ฟ๐—ฑ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—ฑ๐—ฎ๐˜€๐—ต๐—ฒ๐˜€
=> Free Cloud Certifications -GCP

Removes search results that contain your excluded word(s).
๐—ข๐—ป๐—น๐˜† ๐˜€๐—ฒ๐—ฎ๐—ฟ๐—ฐ๐—ต ๐˜๐—ต๐—ฟ๐—ผ๐˜‚๐—ด๐—ต ๐—ฎ ๐˜€๐—ฝ๐—ฒ๐—ฐ๐—ถ๐—ณ๐—ถ๐—ฐ ๐˜€๐—ถ๐˜๐—ฒ
=> NestJS dependency cycle site:stackoverflow.com

Search results from other sites will be removed.
Read 13 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(