2017-01-30 63 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.