Reducing Clojure Lambda Cold Starts Part 2 - VPC

Reducing Clojure Lambda Cold Starts Part 2 - VPC

After my last post Reducing Clojure Lambda Cold Starts Part 1 - Baseline, I remembered that a few years back, Lambdas within a VPC had some pretty terrible cold start times. Doing a comparison seemed like low-hanging fruit so I decided to run the same experiment, but with the Lambda in a VPC:

AWSTemplateFormatVersion: "2010-09-09"

Transform:
- "AWS::Serverless-2016-10-31"

Resources:

  RunCalculationsQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: !Sub "${AWS::StackName}-run-calcs-queue"
      VisibilityTimeout: 5400

  RunCalculations:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub "${AWS::StackName}-run-calcs"
      Handler: tax.core::calculationsHandler
      Runtime: java11
      CodeUri: target/tax-engine-0.1.0-standalone.jar
      Timeout: 900
      MemorySize: 2048
      Policies:
        - AWSLambdaBasicExecutionRole
      Events:
        SQSEvent:
          Type: SQS
          Properties:
            Queue: !GetAtt RunCalculationsQueue.Arn
            BatchSize: 1
      VpcConfig:
        SubnetIds:
          - <<cool subnet 1>>
          - <<cool subnet 2>>
        SecurityGroupIds:
          - <<cool security group>>

Outputs:

  QueueUrl:
    Value: !Ref RunCalculationsQueue

The results were slightly better 2.5750404 seconds over 83 cold starts, but the difference is probably not statistically significant given the low number of trials. So it seems that VPCs are truly no longer an issue, so on to the next experiment.