0

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

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Bakir Jusufbegovic
  • 2,806
  • 4
  • 32
  • 48

1 Answers1

2

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.

Roman Zhuzha
  • 634
  • 7
  • 8