Skip to content

Latest commit

 

History

History
98 lines (76 loc) · 4.53 KB

File metadata and controls

98 lines (76 loc) · 4.53 KB

Deploy Ruby Lambda functions with .zip file archives

To create a container image to deploy your function code, see Using container images with Lambda.

A .zip file archive is a deployment package that contains your function code and dependencies. You must create a .zip file archive if you use the Lambda API to manage functions, or if you need to include libraries and dependencies other than the AWS SDK. You can upload the package directly to Lambda, or you can use an Amazon Simple Storage Service (Amazon S3) bucket, and then upload it to Lambda. If the deployment package is larger than 50 MB, you must use Amazon S3.

If you use the Lambda console editor to author your function, the console manages the deployment package. You can use this method as long as you don't need to add any libraries. You can also use it to update a function that already has libraries in the deployment package, as long as the total size doesn't exceed 3 MB.

Note
To keep your deployment package size small, package your function's dependencies in layers. Layers enable you to manage your dependencies independently, can be used by multiple functions, and can be shared with other accounts. For more information, see AWS Lambda layers.

Topics

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.

    ~/my-function$ zip function.zip function.rb
    
  2. To upload the package, use the update-function-code command.

    ~/my-function$ aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
    {
        "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.

    ~/my-function$ bundle install --path vendor/bundle
    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.

    package$ zip -r function.zip function.rb vendor
      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.

    ~/my-function$ aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
    {
        "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",
        ...
    }