Skip to content

Instantly share code, notes, and snippets.

@karl-cardenas-coding
Last active December 6, 2020 01:02
Show Gist options
  • Save karl-cardenas-coding/cdffce4a3a1e576f542e3aad6cae543a to your computer and use it in GitHub Desktop.
Save karl-cardenas-coding/cdffce4a3a1e576f542e3aad6cae543a to your computer and use it in GitHub Desktop.
################################################
# Lambda Resources Option 3 - Multiple Lambdas
################################################
#In this scenario the Lambda is zipped and upload outside of the terraform execution
resource "aws_lambda_function" "test_lambda" {
s3_bucket = var.code-bucket
s3_key = local.signedSourceList[index(local.trimPrefix, "lambda")]
# ^ Returns "signed/lambda-3ed11736-6655-4448-935d-659cd0428b90.zip"
....
....
}
resource "aws_lambda_function" "test_lambda_2" {
s3_bucket = var.code-bucket
s3_key = local.signedSourceList[index(local.trimPrefix, "postBooks")]
# ^ Returns "signed/postBooks-fa44bbee-9f5b-455d-7cfd-14450e4679d.zip"
....
....
}
data "aws_s3_bucket_objects" "signedLambdas" {
bucket = var.code-bucket
prefix = "signed/"
}
locals {
signedSourceList = data.aws_s3_bucket_objects.signedLambdas.keys
lambdaSource = try(local.signedSourceList[0], null)
trimPrefix = [ for item in local.signedSourceList : split("-", trimprefix(item, "signed/"))[0]]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment