Once upon a time I was the serverless guy at a startup company building lambda functions. My function went into production at 128mb of memory and a timeout of 3 seconds. Because of game had "live races" we would see big spikes in traffic at certain times of the day, and unfortunately I would also see big spikes in the number of errors in the CloudWatch metrics charts... My boss even opened the website during the high volume event and noticed requests to the lambda returning 400 error. In the cloudwatch logs I could norrow down the logs to just the high volume time and see many timeout errors happening during this period. Needless to say, this is not a good look, and you don't want it to happen to you (especially you, future Jim)!
Once you have created and deployed your lambda function it will be visible in the web AWS console. You can always go in and drag the slider / increment the timeout to edit the settings for you lambda function.
Change MemorySize And
I joking call the above approach the "bitchass method" because it takes extra time and manual effort, can be error prone, and just prone to people forgetting to change it. When you introduce multiple environments that multiplies the issues. You have to keep going back to the browser console just to "make sure" the memory settings are ok. BUT, what if there was a way to just automatically deploy and specify in the code config files exactly the memory size and timeout you want it to have so you can just deploy and forget about it? Well yes, there is. If you use AWS's whole CodePipeline / CodeBuild CI / CD pipeline (which I highly recommended trying by scaffolding out a starter project with AWS CodeStar) then you should have a template.yml file in the root of your project. Since I'm building a simple AWS Lambda function right now I have a Resource named HelloWorld with the type AWS::Serverless::Function. Then in the properties I set the memory to 512mb and the timeout to 5 seconds. Below I've copied full code for my current template.yml file, and just in case the code changes you can see the current version of this file here.
Specifying MemorySize and Timeout here is really nice to me because then I never need to go into the browser console and fiddle with things later. When you are finished with the code and about to deploy, regardless of the current settings, you can be sure that your lambda function will be deployed with the settings specified in this template. I think that control, piece of mind, and ability to automate these settings are actually a feather in the cap of AWS. Not too shabby.
I have been known to be so impatient waiting around for AWS CodePipeline to finish that I also add a serverless.yml file to many of my AWS lambda projects so that I can do an "impatient deploy". All you have to do is add two lines in the provider section of the config file. It should look something like the snippet below, and again you can find the full version here.
The posts on this site are written and maintained by Jim Lynch. About Jim...
Want FREE access to
my daily stock tips
Sign up here:
- Triple Gainers
- Rippers N' Dippers
- Growingest Growers