Package: lambada-ln-dev
Lambada (Alpha)A simple way to work with AWS Lambda projects in Python. Heavily inspired and copied fromhttps://github.com/nficano/python-lambdaInstallation$ pip install lambada-againBasic UsageA basic lambda without dependencies.$ tree

â”œâ”€â”€ config.base.yaml    # Base configuration file
â””â”€â”€ config.py           # Handler
â””â”€â”€ service.py          # HandlerInit$ lambada initRun$ lambada run 
$ lambada run  -n lambda-nameIf there is more than onelambdait shows options from where to chose.Invoke remotely$ lambada invoke
$ lambada invoke -n lambda-nameDeploy lambdas and layers$ lambada deploy (deploy all)
$ lambada deploy -n name
$ lambada deploy -c config.qa.yaml
$ lambada deploy -c config.prod.yamlIf there is a layer associated to the lambda in theconfig.yamlwithout a version specified it will update it with the last one.Update lambda configuration$ lambada update-config
$ lambada update-config -c config.qa.yaml
$ lambada update-config -c config.prod.yamlIf there is a layer associated to the lambda in theconfig.yamlwithout a version specified it will update it with the last one.Build$ lambada buildIt will create a zip file in the./distdirectoryFile structureWe need to have a configuration file and a main file to call.With multiples configuration files$ tree

â”œâ”€â”€ config.yaml
â”œâ”€â”€ config.qa.yaml
â”œâ”€â”€ config.prod.yaml
â”œâ”€â”€ requirements.txt
â””â”€â”€ service.pyWe can have parent-child configurationsThe configuration files needs to have the same name. It will build only therequirements.txtat the lambda directory.$ tree

â”œâ”€â”€ requirements.txt
â”œâ”€â”€ lambda-A
â”‚Â Â  â”œâ”€â”€ README.md
â”‚Â Â  â”œâ”€â”€ requirements.txt
â”‚   â””â”€â”€ service.py
â”œâ”€â”€ lambda-B
â”‚Â Â  â”œâ”€â”€ README.md
â”‚Â Â  â”œâ”€â”€ requirements.txt
â”‚   â””â”€â”€ service.py
â”œâ”€â”€ config.yaml
â”œâ”€â”€ config.prod.yaml
â”œâ”€â”€ requirements.txt
â””â”€â”€ README.mdAnd we need to execute the commands in the parent directory and specify the name of the lambda with-n.$ lambada run -n lambda-A
$ lambada deploy -n lambda-A -c config.prod.yaml
$ lambada invoke -n lambda-A -c config.prod.yamlHow to use itRun locally$ lambada run [-n lambda name] [-c configuration file]
$ lambada run
$ lambada run -n lambda-nameConfigurationEvent test file (optional)You can test the lambda locally passing an event input defined in the configuration file as:# path to file.property
test_event: event.inputThis will look for theevent.pyfile in the lambda directory and get theinputproperty from it.lambda-directory$ cat event.py
input = {'test': 'test'}Layers (optional)If we define a local module as a layer it will load the layer so we can call it from our lambda.layers:
  - layer-nameWe need to have the dependencies installed in our local virtual environment.Environment varsYou can pass and override environment variables in the config.yaml using the-eoption.$ lambada run -e var1=value1 -e var2=value2Invoke remotly$ lambada invoke [-n lambda name] [-c configuration file]
$ lambada invoke
$ lambada invoke -n lambda-nameBuildIt will bundle all the dependencies and create adistdirectory with the zip file.$ lambada build [-n lambda name] [-c configuration file]
$ lambada build
$ lambada build -n lambda-nameConfigurationRequirements (optional)If there is a requirements file specified it will install the packages locallyrequirements: requirements.txtDirectories (optional)By default it will add only the directories specified in thedirectoriessection.directories                 
  - srcFiles (optional) (default= all files + main file - directories)By default it will add all the files. You can specify which ones in thefilessection.files:                      # Files we want to include in the root directoy 
  - config.pySymlinkIt will copy thesymlinkinto the bundle.DeployIt will create or update the Lambda and deploy thezipfilecreated in thebuildstep into AWS.$ lambada deploy [-n name] [-c configuration file]Deploy all$ lambada deployDeploy one lambda/layer$ lambada deploy -n nameChoose configuration file$ lambada deploy -c config.file.yamlConfigurationThese values are required in the configuration filename: lambda-function-name
description: Description
region: us-east-1
main_file: service.py
handler: handler
runtime: python3.6
role: lambda_basic_execution

aws_access_key_id: access_key_id
aws_secret_access_key: secret_access_keyDefault valuesmain_file: service.py
handler: handler
runtime: python3.6
role: lambda_basic_executionEnvironment variablesenvironment_variables:
  DB: 'postgresql://postgres:@localhost:5432/template'Security groups and Subnetssecurity_group_ids:
  - sg-123456789

subnet_ids:
  - subnet-a123456789
  - subnet-b123456789Aliasalias: devLayerslayers:
  - ../lib/config.yaml
  - name-of-the-layerInfoIt will print the lambda information$ lambada info [-n lambda name] [-c configuration file]
$ lambada info
$ lambada info -n lambda-nameUpdate configurationIt will update the lambda configuration. Useful if we did only configuration changes.$ lambada update_config [-n lambda name] [-c configuration file]
$ lambada update_config
$ lambada update_config -n lambda-nameConfiguration file example$ cat config.base.yaml
lambdas:
  base:
    abstract: True
    region: us-east-1
    runtime: python3.6
    role: lambda-role
    main_file: service.py
    handler: handler
    # path to file.property
    test_event: event.input

    security_group_ids:
      - sg-12345

    subnet_ids:
      - subnet-1
      - subnet-2

  lambda-test:
    parent: base
    name: function name test
    description: function description
    path: './lambda-test'

    environment_variables:
      DB: 'postgresql://postgres:@localhost:5432/template'
      TEST: 'test'

    directories                 # Directories we want to deploy
      - src

    files:                      # Files we want to include that are in the root directoy 
      - config.py

    # We can specify a local layer or a remote layer
    layers:
      - layer-1

layers:
  layer-1:
    name: layer-1
    runtime: python3.6
    description: Layer-1
    requirements: requirements.txt
    path: layer$ cat config.yaml
aws_access_key_id: access_key_id
aws_secret_access_key: secret_access_key

parent: config.base.yamlLayersWe can alsobuild,deploy,updateand getinfoon layers.LambdaWe can define a layer dependency inside a lambda in two ways.We can specify the name of the layer:layers:
  - name-of-the-layerBy default it will set up the last version of the layer.You can specify a different like this:layers:
  - name-of-the-layer,3Configuration file exampleThe main difference is theis_layerpropertiy is set totrue.name: layer_name
description: Description
is_layer: true
region: us-east-1
main_file: service.py
handler: handler
runtime: python3.6

requirements: requirements.txt
files:
  - utils.py

directories: 
  - lib

aws_access_key_id: access_key_id
aws_secret_access_key: secret_access_key