1. 6
    Create and deploy a lambda function with AWS CDK
    4m 1s

Create and deploy a lambda function with AWS CDK

Share this video with your friends

Send Tweet

It's time to start building our serverless backend!

In this quick lesson we're going to use the lambda.Function construct imported from @aws-cdk/aws-lambda in order to build and deploy a 'Hello World!' AWS Lambda function.

You can find out more about what kind of constructs are available in AWS CDK construct library here

Olga Skurativska
Olga Skurativska
~ 4 years ago

Hey Tomasz, I think you forgot to mention, that before running cdk deploy you also have to run npm run build to compile the code in lambda folder. Otherwise, CDK will just upload just the TypeScript file and it's not going to work in AWS Lambda.

George
George
~ 4 years ago

I had to bootstrap before running cdk deploy. Once that completed I ran cdk deploy and no errors. The exact error message I was getting was: TodoappStack failed: Error: This stack uses assets, so the toolkit stack must be deployed to the environment (Run "cdk bootstrap aws://unknown-account/unknown-region")

Aaron Austin
Aaron Austin
~ 4 years ago

Thanks for this. It was really helpful to get started. One issue I had was using 3rd party node packages (I'm using FaunaDB) in my code. Somehow I missed the description of how to do this in a later lesson. After using my overcomplicated workaround, I found a much better way in lesson 22.

uwinkler
uwinkler
~ 4 years ago

The link to the code seems to be broken - I get a 404

Milan
Milan
~ 4 years ago

Link to code https://github.com/tlakomy/egghead-build-an-app-with-aws-cloud-development-kit/tree/create-a-lamba-function-with-cdk

Lauro Silva
Lauro Silva
~ 4 years ago

Link to code https://github.com/tlakomy/egghead-build-an-app-with-aws-cloud-development-kit/tree/create-a-lamba-function-with-cdk

Thanks for this @Milan! I got the code link updated! 🙌

nadim
nadim
~ 4 years ago

Hello Everyone that is facing problems with deploying their first Lambda Function! If you see this Error message: "failed: Error: This stack uses assets, so the toolkit stack must be deployed to the environment (Run "cdk bootstrap aws://unknown-account/unknown-region")" Just run "cdk bootstrap" and AWS will provide the necessary resources for your environment, details of the process can be found with this AWS docs link => https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html

~ 3 years ago

I'm running this error: lib/todo-app-stack.ts:11:45 - error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'. Type 'TodoAppStack' is missing the following properties from type 'Construct': onValidate, onPrepare, onSynthesize. I've already try to downgrade and upgrade the versions, but is not working. Does anybody knows how to help?

Mike Falanga
Mike Falanga
~ 3 years ago

RE the TypeScript problem above: The lesson here uses v1 of the CDK. v2 is a little different. You just need to npm i aws-sdk-lib -D. To pull in a particular construct, you can do this: import * as lambda from 'aws-cdk-lib/aws-lambda';

If you have the updated types, and the latest version (v2) of aws-cdk and aws-cdk-lib, you'll be good to go!