简体   繁体   English

如何使用AWS Ruby SDK从本地计算机创建AWS Lambda函数

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

I'm having troubles creating request that will create AWS lambda function from local machine. 我在创建将要从本地计算机创建AWS lambda函数的请求时遇到了麻烦。 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. zip_file的位置在文件系统上可以。 I want to upload lambda content from local filesystem without using S3 (I saw there is a way to do that from S3 also). 我想在不使用S3的情况下从本地文件系统上载lambda内容(我也看到有一种从S3做到这一点的方法)。

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 谢谢,巴基尔

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. 根据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.

相关问题 如何使用AWS SDK for Java 2.0创建Lambda函数 - How to create a Lambda function using AWS SDK for Java 2.0 AWS SDK - 如何从用户池创建 lambda function 到 listGroups? - AWS SDK - how to create a lambda function to listGroups from user pool? 如何使用aws ruby​​ SDK为AWS Lambda创建CloudWatch日志触发器? - How to create CloudWatch logs trigger for AWS Lambda using aws ruby SDK? 如何使用 aws 控制台将带有库的 python 代码从 Windows 本地机器上传到 aws lambda - how to upload python code with libraries to aws lambda from windows local machine using aws console 如何使用 aws SDK 为 AWS Lambda 函数创建 CloudWatch 日志触发器? - How to create CloudWatch logs trigger for AWS Lambda function using aws SDK? 如何设置PyCharm以在本地计算机上开发AWS Lambda功能? - How to setup PyCharm to develop AWS Lambda function on local machine? 如何将本地项目库引入 ruby​​ aws lambda 函数? - How to require local project library into ruby aws lambda function? 如何使用ruby aws sdk获取活动的lambda工人数? - How to fetch the number of active lambda workers using ruby aws sdk? 从Ruby SDK调用AWS Lambda函数时如何知道context.fail? - How to know if context.fail when invoking AWS Lambda function from Ruby SDK? 如何使用 AWS CLI 创建 AWS Lambda 函数? - How can I create an AWS Lambda function using the AWS CLI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM