Skip to content

Latest commit

 

History

History
133 lines (99 loc) · 5.93 KB

ruby-package.md

File metadata and controls

133 lines (99 loc) · 5.93 KB

Deploy Ruby Lambda functions with .zip file archives

Your AWS Lambda function's code consists of scripts or compiled programs and their dependencies. You use a deployment package to deploy your function code to Lambda. Lambda supports two types of deployment packages: container images and .zip files.

You can use a built-in ZIP archive utility, or any other ZIP utility (such as 7zip) for your command line tool to create a deployment package.

  • The .zip file must contain your function's code, and any dependencies used to run your function's code (if applicable) on Lambda. If your function depends only on standard libraries, or AWS SDK libraries, you do not need to include the libraries in your .zip file. These libraries are included with our supported Lambda runtime environments.
  • If your .zip file is larger than 50 MB, we recommend uploading it to an Amazon S3 bucket. For more information, see Using other AWS services to build a deployment package.
  • If your .zip file contains C-extension libraries, such as the Pillow (PIL) library, we recommend using the AWS SAM CLI to build a deployment package. For more information, see Lambda deployment packages.

This page describes how to create a .zip file as your deployment package, and then use the .zip file to deploy your function code to Lambda using the AWS Command Line Interface (AWS CLI). To upload your .zip file on the Lambda console, see Deployment packages.

Topics

Prerequisites

The AWS Command Line Interface (AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell. To complete the steps in this section, you need the following:

Tools and libraries

Lambda provides the following tools and libraries for the Ruby runtime:

Tools and libraries for Ruby

Updating a function with no dependencies

To update a function by using the Lambda API, use the UpdateFunctionCode operation. Create an archive that contains your function code, and upload it using the AWS Command Line Interface (AWS CLI).

To update a Ruby function with no dependencies

  1. Create a .zip file archive.

    zip function.zip function.rb
    
  2. To upload the package, use the update-function-code command.

    aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
    

    You should see the following output:

    {
        "FunctionName": "my-function",
        "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
        "Runtime": "ruby2.5",
        "Role": "arn:aws:iam::123456789012:role/lambda-role",
        "Handler": "function.handler",
        "CodeSha256": "Qf0hMc1I2di6YFMi9aXm3JtGTmcDbjniEuiYonYptAk=",
        "Version": "$LATEST",
        "TracingConfig": {
            "Mode": "Active"
        },
        "RevisionId": "983ed1e3-ca8e-434b-8dc1-7d72ebadd83d",
        ...
    }
    

Updating a function with additional dependencies

If your function depends on libraries other than the AWS SDK for Ruby, install them to a local directory with Bundler, and include them in your deployment package.

To update a Ruby function with dependencies

  1. Install libraries in the vendor directory using the bundle command.

    bundle install --path vendor/bundle
    

    You should see the following output:

    Fetching gem metadata from https://rubygems.org/..............
    Resolving dependencies...
    Fetching aws-eventstream 1.0.1
    Installing aws-eventstream 1.0.1
    ...
    

    The --path installs the gems in the project directory instead of the system location, and sets this as the default path for future installations. To later install gems globally, use the --system option.

  2. Create a .zip file archive.

    zip -r function.zip function.rb vendor
    

    You should see the following output:

    adding: function.rb (deflated 37%)
      adding: vendor/ (stored 0%)
      adding: vendor/bundle/ (stored 0%)
      adding: vendor/bundle/ruby/ (stored 0%)
      adding: vendor/bundle/ruby/2.7.0/ (stored 0%)
      adding: vendor/bundle/ruby/2.7.0/build_info/ (stored 0%)
      adding: vendor/bundle/ruby/2.7.0/cache/ (stored 0%)
      adding: vendor/bundle/ruby/2.7.0/cache/aws-eventstream-1.0.1.gem (deflated 36%)
    ...
    
  3. Update the function code.

    aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
    

    You should see the following output:

    {
        "FunctionName": "my-function",
        "FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
        "Runtime": "ruby2.5",
        "Role": "arn:aws:iam::123456789012:role/lambda-role",
        "Handler": "function.handler",
        "CodeSize": 300,
        "CodeSha256": "Qf0hMc1I2di6YFMi9aXm3JtGTmcDbjniEuiYonYptAk=",
        "Version": "$LATEST",
        "RevisionId": "983ed1e3-ca8e-434b-8dc1-7d72ebadd83d",
        ...
    }