Lambda allocates CPU power in proportion to the amount of memory configured. By default, your functions have 128 MB of memory allocated. You can increase that value up to 10 GB. With more CPU resources, your Lambda function's duration might decrease.
You can use tools such as AWS Lambda Power Tuning to test your function at different memory settings to find the one that matches your cost and performance requirements the best.
import{Code,Function,Runtime}from'@aws-cdk/aws-lambda';exportclassMyStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);constmyFunction=newFunction(scope,'MyFunction',{code:Code.fromAsset('src/hello/'),handler:'main.handler',runtime:Runtime.PYTHON_3_8,// Change the function memory sizememorySize:2048,});}}
1 2 3 4 5 6 7 8 910111213141516
{"Resources":{"MyFunction":{"Type":"AWS::Serverless::Function","Properties":{// Required properties"CodeUri":".","Runtime":"python3.8","Handler":"main.handler",// Change the function memory size"MemorySize":2048}}}}
1 2 3 4 5 6 7 8 91011
Resources:MyFunction:Type:AWS::Serverless::FunctionProperties:# Required propertiesCodeUri:.Runtime:python3.8Handler:main.handler# Change the function memory sizeMemorySize:2048
1 2 3 4 5 6 7 8 910
provider:name:aws# Change the memory size across all functionsmemorySize:2048functions:hello:handler:handler.hello# Change the memory size for one functionmemorySize:512
123456789
resource"aws_lambda_function""this"{function_name="my-function"runtime="python3.8"handler="main.handler"filename="function.zip" # Change the default memory size valuememory_size=2048}