簡體   English   中英

如何使用AWS Ruby SDK從本地計算機創建AWS Lambda函數

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

我在創建將要從本地計算機創建AWS lambda函數的請求時遇到了麻煩。 這是我要發送的內容:

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)

zip_file的位置在文件系統上可以。 我想在不使用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)

任何幫助都會很棒。

謝謝,巴基爾

我想,您已經找到答案了,但是為了回答問題,這里您應該做的是:

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. String. The contents of your zip file containing your deployment package.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM