繁体   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