Comments (5)
Hi, I was not able to reproduce your slow cold start with a project deployed via SAM CLI:
SAM CLI
sam init
a Python 3.11 hello world template- Modified the template to add the following resource:
HelloWorldLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: ./layer
CompatibleRuntimes:
- python3.11
CompatibleArchitectures:
- x86_64
Metadata:
BuildMethod: python3.11
The only thing that is inside of ./layer
is a requirements.txt
file with the same dependencies noted in the original issue.
- Modified the hello world function to add the following new properties:
EphemeralStorage:
Size: 512
Layers:
- !Ref HelloWorldLayer
- Update the handler to import a package that is defined from the layer (just import, not using any methods)
- Ran
sam build -u
- Ran
sam deploy
- Ran
sam remote invoke
$ sam remote invoke --stack-name sam-app-6715-2
Invoking Lambda Function HelloWorldFunction
START RequestId: ee5bfe82-1b21-4c20-af40-fc9eaea477c3 Version: $LATEST
END RequestId: ee5bfe82-1b21-4c20-af40-fc9eaea477c3
REPORT RequestId: ee5bfe82-1b21-4c20-af40-fc9eaea477c3 Duration: 1.43 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 76 MB Init Duration: 679.37 ms
{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}%
AWS CLI
When creating a Lambda manually via the AWS CLI:
- Zipped the function and layer built directory from previous
sam build
- Create a Lambda layer:
aws lambda publish-layer-version --layer-name manual-layer3 --zip-file fileb://hellolayer.zip --compatible-runtimes python3.11 --compatible-architectures x86_64
- Create a Lambda function:
aws lambda create-function --function-name manual3 --role <some role that is able to `InvokeFunction`> --layers <layer ARN from previous command> --zip-file fileb://hellofunction.zip --handler app.lambda_handler --runtime python3.11 --ephemeral-storage Size=512
- Invoke the Lambda function
$ aws lambda invoke --function-name manual3 /dev/stdout
{"statusCode": 200, "body": "{\"message\": \"hello world\"}"}%
Inspecting the Cloudwatch logs for the function, we can see that the init time is roughly the same as one the one deployed with SAM CLI:
REPORT RequestId: 44daa145-cf6f-4ccb-a86c-379107756e76 Duration: 1.54 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 76 MB Init Duration: 665.80 ms
Is there a reproducible project that you can share somewhere where we can reproduce this? Something interesting to point out, is that in your function runtime logs it looks like the memory is being maxed out. This may have something to do with the slow init times?
from aws-sam-cli.
Found the issue. It was because of same module importing twice in a python file which was in the layer.
import phonenumbers
from phonenumbers import geocoder, carrier, timezone
removed second line. Then init duration during warm up reduced from 5s to 0.5s. Also Max Memory Used gone down from 250MB to 70MB.
from aws-sam-cli.
Hi @AmruthjithSunil, glad you found the issue. Does that address your concerns when running sam commands now?
from aws-sam-cli.
Closing as the issue seems to be resolved.
from aws-sam-cli.
⚠️ COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
from aws-sam-cli.
Related Issues (20)
- SAM build crashes using terraform HOT 9
- Bug: sam local start-api - AttributeError HOT 9
- SAM local invocation with CDK generated template with typescript not able to find module index (index.mjs) HOT 5
- How to add tags with sam deploy HOT 12
- Bug: Got issue when using 1.116.0_1 for deployment HOT 2
- Bug: [WinError 3] The system cannot find the path specified HOT 4
- Feature request: Deploy Lambdas with concurrency HOT 3
- Bug: sam sync with python causes endless cpu saturation HOT 11
- Bug: sam build - EmptyKeyError HOT 1
- Bug: Unable to run sam local invoke on Apple Silicon HOT 14
- Cannot sam local start-api without specifying an image HOT 1
- Bug: sam local start-api - ReadTimeout HOT 3
- Bug: "Timed out while attempting to establish a connection to the container" error after fresh install of Docker and AWS SAM HOT 5
- Bug: sam build - JSONDecodeError HOT 1
- Bug: No new Lambda Versions are deployed with Lambda configurations changes HOT 2
- Bug: Change Parameter's Default value doesn't reflect HOT 4
- Bug: AWS ADOT LAMBDA layer stuck when using local invoke HOT 5
- Bug: AWS::Serverless::Function `ImageUri` with map (ex: using `!Sub`) fails with type error HOT 7
- Bug: Lambda function (with alias) doesn't create a new version after its layer is updated, even if `AutoPublishAliasAllProperties` is set to `true`
- Access to internal enterprise host (Github entreprise) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sam-cli.