Terraform-通过别名调用lambda的URI是什么?

时间:2018-08-31 06:08:25

标签: aws-lambda terraform

问题

要从API GW调用Lambda,invoke_arn可以用于aws_lambda_function资源。

  

invoke_arn-用于从API网关调用Lambda函数的ARN。

resource "aws_api_gateway_integration" "videos" {
  rest_api_id = "${aws_api_gateway_rest_api.24_hour_video.id}"
  resource_id = "${aws_api_gateway_method.videos_get.resource_id}"
  http_method = "${aws_api_gateway_method.videos_get.http_method}"

  integration_http_method = "GET"
  type                    = "AWS_PROXY"  # Lambda Proxy
  uri                     = "${aws_lambda_function.list_videos.invoke_arn}"
}

uri 中设置什么以通过别名调用相同的lambda?

resource "aws_lambda_alias" "lambda_alias_list_videos" {
  name             = "get_video_list"
  description      = "Alias to lambda_list_videos"
  function_name    = "${aws_lambda_function.list_videos.arn}"
  function_version = "$LATEST"
}

2 个答案:

答案 0 :(得分:2)

aws_lambda_alias资源创建一个别名,该别名指向Lambda函数的特定版本。别名本身是不可调用的。

相反,您应该创建一个指向别名版本的aws_lambda_function数据源,并使用其invoke_arn属性。您可以在qualifier中使用aws_lambda_function参数来指定版本或别名(有关更多信息,请参见AWS Lambda Invoke Docs)。

您的示例显示您已经创建了一个名为 get_video_list 的别名,该别名指向 $ LATEST 版本。您需要创建一个指向该别名的新数据源:

data "aws_lambda_function" "my_function_get_video_list" {
  function_name = "your-function-name"
  qualifier = "get_video_list"
}

您现在可以获取别名函数的调用ARN:

${aws_lambda_function.my_function.get_video_list.invoke_arn}

答案 1 :(得分:1)

import wx class TopPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent=parent) Main = parent.GetParent() self.btm = Main.bottom self.label = wx.StaticText(self, label='Choose your animal:', pos=(10, 30)) animals = ["dog", "cat", "mouse"] self.combobox = wx.ComboBox(self, choices=animals, pos=(10, 50)) self.label2 = wx.StaticText(self, label="", pos=(10, 80)) self.combobox.Bind(wx.EVT_COMBOBOX, self.onCombo) def onCombo(self, event): comboValue = self.combobox.GetValue() self.label2.SetLabel("Chosen animal: " + comboValue) self.btm.changeLabel(event, comboValue) class BottomPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent=parent) self.SetBackgroundColour("grey") self.bottomLabel = wx.StaticText(self, label="MyBottomLabel", pos=(10, 50)) def changeLabel(self, event, passedText): self.bottomLabel.SetLabel(passedText) print(passedText) class Main(wx.Frame): def __init__(self): wx.Frame.__init__(self, parent=None, title="Generator", size=(500, 500)) self.splitter = wx.SplitterWindow(self) self.bottom = BottomPanel(self.splitter) self.top = TopPanel(self.splitter) self.splitter.SplitHorizontally(self.top, self.bottom) self.splitter.SetMinimumPaneSize(250) if __name__ == "__main__": app = wx.App(False) frame = Main() frame.Show() app.MainLoop() 资源具有aws_lambda_alias属性(请参阅docs),该属性是为API网关设计的。例如:

invoke_arn