Skip to main content

Helpers to deploy lambda functions in an immutable way

Project description

lambda_freezer

Goals:

  • Make it easy to deploy one or many services under the same Amazon API Gateway.
  • Make it easy to deploy a stage in an immutable way.

Deploy a specific stage

The main aim of this module is to help your Amazon API Gateway work in such a way that each stage is immutable. This is achieved by using the versioning and aliasing features of Lambda function, as well as stage variables. The gist is this:

  • When deploying a stage, each underlying Lambda function is frozen to a specific version.
  • When calling the resouces for that particular stage, the "frozen" versioning of Lambda functions will be called (indirectly via an alias).

For more information of how that is achieved "manually" in more details: https://aws.amazon.com/blogs/compute/using-api-gateway-stage-variables-to-manage-lambda-functions/

Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lambda_freezer
>>> REST_API_ID = "r5ltm5nqr6"
>>> REGION = "us-east-1"
>>> DOMAIN_NAME = "api-library.puno.io" # this guy is optional
>>> deploy(REST_API_ID, REGION, "0.0.1", "some description", DOMAIN_NAME)

Flow (super opinionated)

  • use serverless framework and configure like something below.
 - provider:
      name: aws
      runtime: python3.6
      stage: latest # THIS IS SUPER IMPORTANT - CANNOT BE ANYTHING ELSE
      versionFunctions: false # versioning would be done only upon deploying/"freezing" to a stage
      apiGateway: # make sure you point to a common api gateway
        restApiId:
          'Fn::ImportValue': 'OUTPUT-ApiGatewayRestApiId-REPLACE-WITH-OWN'
        restApiRootResourceId:
          'Fn::ImportValue': 'OUTPUT-ApiGatewayRestApiRootResourceId-REPLACE-WITH-OWN'
  • To push your functions and make sure the api gateway integration gets changed. (We want that every function integrations' are such that the api gateway can only call a specific version of any lambda functions via an alias, using a stage variable).
serverless deploy
Python 3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lambda_freezer
>>> REST_API_ID = "r5ltm5nqr6"
>>> REGION = "us-east-1"
>>> DOMAIN_NAME = "api-library.puno.io" # this guy is optional
>>> run_after_default_deployment(REST_API_ID, REGION, DOMAIN_NAME)
  • When you like a specific version of your functions, just "freeze" them using the deploy cmd described above.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lambda-freezer-0.0.6.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

lambda_freezer-0.0.6-py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page