[{"data":1,"prerenderedAt":154},["ShallowReactive",2],{"content-svc-lambda-paved-path-java-replatforming-snapstart":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":30,"menu":31,"menuType":150,"isCollapseableMenu":34,"nextDocItem":90,"previousDocItem":57,"contributorPaths":151,"contentName":153,"slug":86,"readingTime":50},"\u003Cp>\u003Cstrong>SnapStart\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cp>For latency-sensitive functions where most latency is caused by cold starts, Lambda SnapStart for Java can improve \nstartup performance by up to 10x. With SnapStart, Lambda initializes your function when you create a Lambda Version. \nLambda then takes a snapshot of the entire environment and stores it in a multi-tiered cache. When a function needs to \ncreate a new execution environment, it does so by restoring the snapshot, this results in much faster start-up times. \nThere is no additional cost for using SnapStart.\u003C\u002Fp>\n\u003Cp>The \u003Ca href=\"https:\u002F\u002Fcatalog.workshops.aws\u002Fjava-on-aws-lambda\u002Fen-US\u002F03-snapstart\">Starting up faster with AWS Lambda SnapStart\u003C\u002Fa>\nworkshop gives you a step-by-step guide of how SnapStart addresses Java function performance, how to enable SnapStart \nwith IaC, and how to customize your SnapStart behavior with runtime hooks.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Stale TCP connections\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Cp>Your function will be snapshotted once the initialization phase is complete. If in that phase you create TCP connections, \nfor example, to Redis, Postgres or MySQL, then the snapshot will keep this state. When your function is restored on \nanother host, which could also be days or weeks later, then there will be no TCP connection. The error handling of your \nclient library will most likely handle this stale connection and recreate it.\u003C\u002Fp>\n\u003Cp>You can proactively manage this by using \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Fsnapstart-runtime-hooks.html\">SnapStart runtime hooks\u003C\u002Fa>. They allow you to run code just before and just after the snapshotting process. You can then write a hook to close any open TCP connections made by client libraries you are using.\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-java\">import org.crac.Core;\nimport org.crac.Resource;\n\npublic class Example implements RequestHandler&lt;Object, Object&gt;, Resource {\n\n    public Example() {\n        Core.getGlobalContext().register(this);\n    }\n    \n    @Override\n    public Object handleRequest(Object input, Context context) {\n        \n    }\n    \n    @Override\n    public void beforeCheckpoint(org.crac.Context&lt;? extends Resource&gt; context) throws Exception {\n        \u002F\u002F Close any open connections\n    }\n    \n    @Override\n    public void afterRestore(org.crac.Context&lt;? extends Resource&gt; context) throws Exception {\n        \u002F\u002F Restart connections\n    }\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n",{"title":6,"youtubeVideoID":7,"order":8,"callout":9,"resources":13,"learningGoals":28},"Performance - SnapStart","ZbnAithBNYY",2,{"title":10,"description":11,"link":12},"Workshop","Learn how SnapStart addresses Java function performance, how to enable SnapStart with IaC, and how to customize your SnapStart behavior with runtime hooks.","https:\u002F\u002Fcatalog.workshops.aws\u002Fjava-on-aws-lambda\u002Fen-US\u002F03-snapstart",[14,18,21,25],{"link":15,"text":16,"type":17},"https:\u002F\u002Fserverlessland.com\u002Fpatterns\u002Fapigw-lambda-snapstart","API Gateway to Lambda with SnapStart","Pattern",{"link":19,"type":17,"text":20},"https:\u002F\u002Fserverlessland.com\u002Fpatterns\u002Fapigw-lambda-rds-snapstart","REST API with Amazon API Gateway, Amazon RDS and AWS Lambda with SnapStart",{"link":22,"type":23,"text":24},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fstarting-up-faster-with-aws-lambda-snapstart\u002F?ref=serverlessland","Blog","Starting up faster with AWS Lambda SnapStart",{"link":26,"type":23,"text":27},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Freducing-java-cold-starts-on-aws-lambda-functions-with-snapstart\u002F?ref=serverlessland","Reducing Java cold starts on AWS Lambda functions with SnapStart",[29],"Learn how Lambda SnapStart improves first invoke latency","**SnapStart**\n\nFor latency-sensitive functions where most latency is caused by cold starts, Lambda SnapStart for Java can improve \nstartup performance by up to 10x. With SnapStart, Lambda initializes your function when you create a Lambda Version. \nLambda then takes a snapshot of the entire environment and stores it in a multi-tiered cache. When a function needs to \ncreate a new execution environment, it does so by restoring the snapshot, this results in much faster start-up times. \nThere is no additional cost for using SnapStart.\n\nThe [Starting up faster with AWS Lambda SnapStart](https:\u002F\u002Fcatalog.workshops.aws\u002Fjava-on-aws-lambda\u002Fen-US\u002F03-snapstart)\nworkshop gives you a step-by-step guide of how SnapStart addresses Java function performance, how to enable SnapStart \nwith IaC, and how to customize your SnapStart behavior with runtime hooks.\n\n**Stale TCP connections**\n\nYour function will be snapshotted once the initialization phase is complete. If in that phase you create TCP connections, \nfor example, to Redis, Postgres or MySQL, then the snapshot will keep this state. When your function is restored on \nanother host, which could also be days or weeks later, then there will be no TCP connection. The error handling of your \nclient library will most likely handle this stale connection and recreate it.\n\nYou can proactively manage this by using [SnapStart runtime hooks](https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Fsnapstart-runtime-hooks.html). They allow you to run code just before and just after the snapshotting process. You can then write a hook to close any open TCP connections made by client libraries you are using.\n\n```java\nimport org.crac.Core;\nimport org.crac.Resource;\n\npublic class Example implements RequestHandler\u003CObject, Object>, Resource {\n\n    public Example() {\n        Core.getGlobalContext().register(this);\n    }\n    \n    @Override\n    public Object handleRequest(Object input, Context context) {\n        \n    }\n    \n    @Override\n    public void beforeCheckpoint(org.crac.Context\u003C? extends Resource> context) throws Exception {\n        \u002F\u002F Close any open connections\n    }\n    \n    @Override\n    public void afterRestore(org.crac.Context\u003C? extends Resource> context) throws Exception {\n        \u002F\u002F Restart connections\n    }\n}\n```",[32,54,73,87,104,116,140],{"title":33,"collapsible":34,"isCollapsed":35,"content":36},"Introduction",false,true,[37],{"title":33,"order":38,"callout":39,"prerequisite":42,"resources":45,"time":50,"path":51,"id":52,"link":53},1,{"title":10,"description":40,"link":41},"The workshop gives you a step-by-step guide of how to migrate a Spring Boot application to Lambda using the AWS Serverless Java Container library.","https:\u002F\u002Fcatalog.workshops.aws\u002Fjava-on-aws-lambda\u002Fen-US\u002F01-migration",[43,44],"Some understanding of Java","Some Understanding of AWS Lambda",[46],{"link":47,"text":48,"type":49},"https:\u002F\u002Faws.amazon.com\u002Flambda\u002F","Learn more about Lambda","text","2 min","introduction","introduction.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Fintroduction",{"title":55,"collapsible":34,"isCollapsed":35,"content":56},"Access patterns",[57],{"title":58,"order":8,"callout":59,"resources":60,"learningGoals":68,"time":50,"path":70,"id":71,"link":72},"Access Patterns",{"title":10,"description":40,"link":41},[61,65],{"link":62,"type":63,"text":64},"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-lambda-web-adapter","Repo","AWS Lambda Web Adapter",{"link":66,"text":67,"type":63},"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-serverless-java-container","AWS Serverless Java Container",[69],"To learn the different approaches to replatforming REST APIs on Lambda","access-patterns","access-patterns.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Faccess-patterns",{"title":74,"collapsible":34,"isCollapsed":34,"content":75},"SnapStart",[76],{"title":6,"youtubeVideoID":7,"order":8,"callout":77,"resources":78,"learningGoals":83,"time":50,"path":84,"id":85,"link":86},{"title":10,"description":11,"link":12},[79,80,81,82],{"link":15,"text":16,"type":17},{"link":19,"type":17,"text":20},{"link":22,"type":23,"text":24},{"link":26,"type":23,"text":27},[29],"snapstart","snapstart.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Fsnapstart",{"title":88,"collapsible":34,"isCollapsed":35,"content":89},"Performance",[90],{"title":88,"youtubeVideoID":91,"order":8,"callout":92,"resources":94,"learningGoals":98,"time":100,"path":101,"id":102,"link":103},"sVJOJUD0fhQ",{"title":10,"description":93,"link":41},"Learn how to optimize Java Lambda functions.",[95],{"link":96,"type":23,"text":97},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Foptimizing-aws-lambda-function-performance-for-java\u002F?ref=serverlessland","Optimizing AWS Lambda function performance for Java",[99],"How to optimization your Java function","1 min","performance","performance.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Fperformance",{"title":105,"collapsible":34,"isCollapsed":35,"content":106},"Observability - Logging ",[107],{"title":108,"order":8,"callout":109,"learningGoals":110,"time":112,"path":113,"id":114,"link":115},"Observability - Logging",{"title":10,"description":40,"link":41},[111],"How to meet your logging requirements with Lambda","4 min","observability-and-logging","observability-and-logging.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Fobservability-and-logging",{"title":117,"collapsible":34,"isCollapsed":35,"content":118},"Observability - Metrics",[119],{"title":117,"order":8,"callout":120,"resources":124,"learningGoals":134,"time":136,"path":137,"id":138,"link":139},{"title":121,"description":122,"link":123},"Watch the video","AWS Lambda Powertools: Lessons from the road to 10 million downloads.","https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=dH2GP6Lydj8",[125,128,131],{"link":126,"text":127,"type":63},"https:\u002F\u002Fawslabs.github.io\u002Faws-lambda-powertools-java\u002Fcore\u002Fmetrics\u002F","Lambda Powertools for Java - Metrics",{"link":129,"text":130,"type":63},"https:\u002F\u002Fawslabs.github.io\u002Faws-lambda-powertools-java\u002F","Lambda Powertools for Java",{"link":132,"text":133,"type":63},"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Faws-embedded-metrics-java","EMF Client Library",[135],"How to efficiently write metrics with Lambda","3 min","metrics","metrics.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Fmetrics",{"title":141,"collapsible":34,"isCollapsed":35,"content":142},"Health checks",[143],{"title":144,"order":8,"learningGoals":145,"time":100,"path":147,"id":148,"link":149},"Health Checks",[146],"To understand when to use health checks with Lambda","health-checks","health-checks.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Fhealth-checks","LESSON",[152],"content\u002Fcontributors\u002Fmark-sailes.json","Java Replatforming",1792578874777]