简体   繁体   中英

How to create AWS lambda function from local machine using AWS Ruby SDK

I'm having troubles creating request that will create AWS lambda function from local machine. This is the content that I'm trying to send:

require 'aws-sdk'

client = Aws::Lambda::Client.new(region: 'us-east-1')

args = {}
args[:role] = role
args[:function_name] = function_name
args[:handler] = handler
args[:runtime] = 'python2.7'
code = {}
code[:zip_file] = '/root/main.zip'
args[:code] = code

client.create_function(args)

Location of zip_file is ok on filesystem. I want to upload lambda content from local filesystem without using S3 (I saw there is a way to do that from S3 also).

The error I'm getting is:

lib/ruby/gems/2.0.0/gems/aws-sdk-core-2.5.11/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call': Could not unzip uploaded file. Please check your file, then try to upload again. (Aws::Lambda::Errors::InvalidParameterValueException)

Any help would be great.

Thanks, Bakir

I guess, you've already found it out, but just for the sake of question to be answered here is what you should've done:

require 'aws-sdk'

client = Aws::Lambda::Client.new(region: 'us-east-1')

args = {}
args[:role] = role
args[:function_name] = function_name
args[:handler] = handler
args[:runtime] = 'python2.7'
code = {}
code[:zip_file] = File.open('main.zip', 'rb').read
args[:code] = code

client.create_function(args)

According to Aws::Lambda::Client docs, option :code is a Types::FunctionCode type, where zip_file is a String. The contents of your zip file containing your deployment package. String. The contents of your zip file containing your deployment package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM