Lono Uploaded Files

Lono can automatically upload files to s3 and make them available to reference in your CloudFormation templates as a part of lono up. This is particularly useful for Lambda functions.

Lambda Function Example

The file or files get zipped and uploaded to s3.


def lambda_handler(event:, context:)
  puts "hello"

In the template definition, you reference the uploaded file like so


resource("Function", "AWS::Lambda::Function",
  Code: {
    S3Bucket: files_bucket, # same as lono bucket
    S3Key: files("files/index.rb"), # use files/index.rb
  Handler: "index.lambda_handler",
  Role: get_att("LambdaExecutionRole.Arn"),
  Runtime: "ruby2.7",
  Timeout: "300"

The files only get uploaded if the method files is called in your templates. Lono zip ups the file to work with Lambda.

Zipping Folders

If pass files a folder instead of a file, lono zips up the entire contents within the folder to work with Lambda.

Templating Support

ERB Template is also supported in app files. To activate ERB support, add a .tt extension to the file name. Lono processes the .tt files as ERB files and the .tt extension will be removed from the resulting final file. You have access to your Variables and Helpers.



require 'json'

def lambda_handler(event:, context:)
  # <%= "comment is from erb" %>
  { statusCode: 200, body: JSON.generate('Hello from Lambda!') }

Results in:


require 'json'

def lambda_handler(event:, context:)
  # comment is from erb
  { statusCode: 200, body: JSON.generate('Hello from Lambda!') }