Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 1.30 KB | None | 0 0
  1. ######### Here in main.tf  we use module to create lambda function and invoke it:
  2.  
  3. module "get_params" {
  4.   source                    = "../../modules/lambda"
  5.   file_name                 = module.get_params_archive.path
  6.   lambda_function_file_name = "get_params"
  7.   function_name             = "get_params"
  8.  
  9.   invocation = "true"
  10.  
  11.   environment = merge(map(
  12.     "project", local.project,
  13.     "query", "[ \"key1\", \"key2\" ]"
  14.   ))
  15.  
  16. }
  17.  
  18. ######### This is in "../../modules/lambda" files, shortened:
  19. ### the function creation
  20. resource "aws_lambda_function" "this" {
  21.   filename                       = var.file_name
  22.   function_name                  = local.name
  23.   ...  
  24. }
  25.  
  26. ### invocation (var.creation is true)
  27. data "aws_lambda_invocation" "this" {
  28.   count = var.invocation == "true" && var.creation == "true" ? 1 : 0
  29.   function_name = aws_lambda_function.this.function_name
  30.  
  31.   input = <<JSON
  32. {
  33.   "Name": "Invocation"
  34. }
  35. JSON
  36. }
  37.  
  38. ### output of the module
  39. output "result_map" {
  40.   description = "if result is a map"
  41.   value = data.aws_lambda_invocation.this.*.result_map  
  42. }
  43.  
  44. ######### return back to the main code: here's how I get the output to check we have at least something and the lambda works :
  45.  
  46. output "out_params_map" {
  47.  description = "something"
  48.  value = module.get_params.result_map
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement