AWS Code Sample
Catalog

aws-ruby-sdk-lambda-example-run-function.rb

Runs a Lambda function.

# Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # http://aws.amazon.com/apache2.0/ # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. require 'aws-sdk-lambda' # v2: require 'aws-sdk' require 'json' # To run on Windows: require 'os' if OS.windows? Aws.use_bundled_cert! end client = Aws::Lambda::Client.new(region: 'us-west-2') # Get the 10 most recent items req_payload = {:SortBy => 'time', :SortOrder => 'descending', :NumberToGet => 10} payload = JSON.generate(req_payload) resp = client.invoke({ function_name: 'MyGetItemsFunction', invocation_type: 'RequestResponse', log_type: 'None', payload: payload }) resp_payload = JSON.parse(resp.payload.string) # , symbolize_names: true) # If the status code is 200, the call succeeded if resp_payload["statusCode"] == 200 # If the result is success, we got our items if resp_payload["body"]["result"] == "success" # Print out items resp_payload["body"]["data"].each do |item| puts item end end end

Sample Details

Service: lambda

Last tested: 2018-03-16

Author: Doug-AWS

Type: full-example

On this page: