-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hendrix Roa
committed
Dec 27, 2019
1 parent
2d675d6
commit 87a32ee
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Lambda Node.js + yarn | ||
|
||
Lambda Module with the best security practice prebuilt with yarn installing to add custom modules and libreries from npmjs.com, ideally to integrate to CI/CD pipeline. Some features: | ||
|
||
- Integrated with S3 bucket to deploy latest version and compare if a lambda require update. | ||
- Best security best practices witn encryption features. | ||
- Easy handle to packaging zip + node_modules folder. | ||
- Terraform `0.12.+` | ||
|
||
## How to use | ||
|
||
```hcl | ||
module "my-lambda" { | ||
source = "hendrixroa/lambda-nodejs-yarn/aws" | ||
code_location = "../mylambdas/lambda" | ||
key_s3_bucket = "lambda.zip" | ||
s3_bucket_id = aws_s3_bucket.lambdas.id | ||
lambda_iam_role = aws_iam_role.lambda_basic_role.arn | ||
lambda_function_name = "lambda" | ||
lambda_runtime = "nodejs10.x" | ||
kms_key_logs = "kms key arn for logs" | ||
kms_key_lambda = "kms key arn for lambda" | ||
environment_variables = { | ||
myAwesomeEnv = "my awesome value" | ||
} | ||
} | ||
``` | ||
|
||
- Basic IAM Role and Policy: | ||
|
||
```hcl | ||
resource "aws_iam_role" "lambda_basic_role" { | ||
name = "lambda_basic_role" | ||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
}, | ||
"Effect": "Allow" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
resource "aws_iam_role_policy" "lambda_basic_policy" { | ||
name = "lambda_basic_policy" | ||
role = aws_iam_role.lambda_basic_role.id | ||
policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents" | ||
], | ||
"Resource": [ | ||
"arn:aws:logs:*:*:*" | ||
] | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
``` |