2017-01-30 124 views
0

我遇到了创建请求的麻烦,该请求将从本地机器创建AWS lambda函数。这是我尝试发送内容:如何使用AWS Ruby SDK从本地机器创建AWS lambda函数

zip_file的
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) 

位置是在文件系统中确定。我想在不使用S3的情况下从本地文件系统上传lambda内容(我看到有一种方法可以从S3中执行此操作)。

我得到的错误是:

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) 

任何帮助将是巨大的。

感谢, 巴克尔

回答

1

我想,你已经发现了这件事,但只是问题在这里得到解答的缘故是你应该做了什么:

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) 

根据到Aws::Lambda::Client文档,选项:codeTypes::FunctionCode类型,其中zip_fileString. The contents of your zip file containing your deployment package.