Every resource we deploy to AWS with CDK has some default values configured for us so that we don't have to configure everything ourselves.
This comes in handy because it allows us to focus on building our infrastructure and solving our problems instead of configuring everything.
With that being said - CDK allows us to configure various properties of our resources! In this quick lesson we're going to learn how to configure the memory size and timeout of an AWS Lambda function.
Instructor: [0:00] We have a Lambda function deployed to CDK and we can see over here that it has some basic settings such as the memory size, which was set to 128 MB, and also timeout which was set to three seconds by default. Of course, we can modify those default values. The cool thing about CDK is that we don't have to open up the documentation in order to do that.
[0:17] If I go over here and expand the list of all available properties for Lambda function and if I search for memory, we're going to see that in order to change the memory size available for Lambda function, we have to use the memory set property. It is a number and the default value is 128 MB. Let me do that and change it to 256.
[0:34] Next stop, the timeout. If I press T, it's going to show me the timeout. Here we can see a snippet of the documentation. This is the function execution time in seconds after which the Lambda is going to terminate the function.
[0:46] We can set it up to 15 minutes, but it is not such a good idea because what happens is that if your function is going to get stuck because of something, we'll end up paying for the 15 minutes of the Lambda function execution, and this can get rather expensive. I'm going to set the timeout to CDK duration of seconds and I'm going to set it to 10 seconds.
[1:06] We can open up the terminal and then run cdk diff to see what we are about to deploy. We can see that our function is going to stay exactly the same. The only thing that is going to change is the memory size and also the timeout. Let me clear the terminal and run cdk deploy.
[1:19] Once this is done, we can go back to AWS Console to see that both the memory size and also the timeout was updated according to the settings that we have configured over here.