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

时间:2017-01-30 11:59:16

标签: amazon-web-services aws-lambda aws-sdk-ruby

我遇到了创建请求的麻烦,该请求将从本地计算机创建AWS lambda函数。这是我试图发送的内容:

# prepare some random vectors with different lengths
myNumericVectorOfLength221 <- rnorm(221)
myNumericVectorOfLength200 <- rnorm(220)

# create a multi dimensional list
dataset <- array(list(),dim=c(3,2))
rownames(dataset) <- c("original","zscores","smoothed")
colnames(dataset) <- c("front", "side")

# fill some cells
dataset[["original", "side"]] <- vec10
dataset[["zscores","front"]] <- vec3

# let's see the whole matrix
> dataset
         front     side      
original NULL      Integer,10
zscores  Integer,3 NULL      
smoothed NULL      NULL

# let's get one of the added vector
> dataset[["original", "side"]]
[1]  1  2  3  4  5  6  7  8  9 10

zip_file的位置在文件系统上是可以的。我想在不使用S3的情况下从本地文件系统上传lambda内容(我看到有办法从S3那里做到这一点)。

我得到的错误是:

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)

任何帮助都会很棒。

谢谢, 巴克尔

1 个答案:

答案 0 :(得分:2)

我想,你已经发现了它,但只是为了回答这个问题,你应该做的就是:

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.