-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example 's3-custom-kms-key' and update documentation
New example 's3-custom-kms-key' was added and mentioned in the main README
- Loading branch information
Showing
8 changed files
with
222 additions
and
5 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
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 @@ | ||
builds/* |
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,69 @@ | ||
# AWS Lambda Function with custom KMS key encryption in S3 | ||
|
||
Configuration in this directory creates AWS Lambda Function that is uploaded to S3 using a self-managed KMS key. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.63 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.63 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | ../../ | n/a | | ||
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_kms_key.objects](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_lambda_cloudwatch_log_group_arn"></a> [lambda\_cloudwatch\_log\_group\_arn](#output\_lambda\_cloudwatch\_log\_group\_arn) | The ARN of the Cloudwatch Log Group | | ||
| <a name="output_lambda_function_arn"></a> [lambda\_function\_arn](#output\_lambda\_function\_arn) | The ARN of the Lambda Function | | ||
| <a name="output_lambda_function_arn_static"></a> [lambda\_function\_arn\_static](#output\_lambda\_function\_arn\_static) | The static ARN of the Lambda Function. Use this to avoid cycle errors between resources (e.g., Step Functions) | | ||
| <a name="output_lambda_function_invoke_arn"></a> [lambda\_function\_invoke\_arn](#output\_lambda\_function\_invoke\_arn) | The Invoke ARN of the Lambda Function | | ||
| <a name="output_lambda_function_last_modified"></a> [lambda\_function\_last\_modified](#output\_lambda\_function\_last\_modified) | The date Lambda Function resource was last modified | | ||
| <a name="output_lambda_function_name"></a> [lambda\_function\_name](#output\_lambda\_function\_name) | The name of the Lambda Function | | ||
| <a name="output_lambda_function_qualified_arn"></a> [lambda\_function\_qualified\_arn](#output\_lambda\_function\_qualified\_arn) | The ARN identifying your Lambda Function Version | | ||
| <a name="output_lambda_function_qualified_invoke_arn"></a> [lambda\_function\_qualified\_invoke\_arn](#output\_lambda\_function\_qualified\_invoke\_arn) | The Invoke ARN identifying your Lambda Function Version | | ||
| <a name="output_lambda_function_source_code_hash"></a> [lambda\_function\_source\_code\_hash](#output\_lambda\_function\_source\_code\_hash) | Base64-encoded representation of raw SHA-256 sum of the zip file | | ||
| <a name="output_lambda_function_source_code_size"></a> [lambda\_function\_source\_code\_size](#output\_lambda\_function\_source\_code\_size) | The size in bytes of the function .zip file | | ||
| <a name="output_lambda_function_version"></a> [lambda\_function\_version](#output\_lambda\_function\_version) | Latest published version of Lambda Function | | ||
| <a name="output_lambda_role_arn"></a> [lambda\_role\_arn](#output\_lambda\_role\_arn) | The ARN of the IAM role created for the Lambda Function | | ||
| <a name="output_lambda_role_name"></a> [lambda\_role\_name](#output\_lambda\_role\_name) | The name of the IAM role created for the Lambda Function | | ||
| <a name="output_s3_object"></a> [s3\_object](#output\_s3\_object) | The map with S3 object data of zip archive deployed (if deployment was from S3) | | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
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,57 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
|
||
# Make it faster by skipping something | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
} | ||
|
||
module "lambda_function" { | ||
source = "../../" | ||
|
||
function_name = "${random_pet.this.id}-lambda-s3-custom-kms-key" | ||
handler = "index.lambda_handler" | ||
runtime = "python3.8" | ||
source_path = "${path.module}/../fixtures/python3.8-app1" | ||
|
||
store_on_s3 = true | ||
s3_bucket = module.s3_bucket.s3_bucket_id | ||
s3_prefix = "lambda-builds/" | ||
|
||
# Upload to S3 using our self-managed KMS key | ||
s3_kms_key_id = aws_kms_key.objects.arn | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
resource "aws_kms_key" "objects" { | ||
description = "KMS key used to encrypt bucket objects" | ||
deletion_window_in_days = 7 | ||
} | ||
|
||
module "s3_bucket" { | ||
source = "terraform-aws-modules/s3-bucket/aws" | ||
version = "~> 3.0" | ||
|
||
bucket_prefix = "${random_pet.this.id}-" | ||
force_destroy = true | ||
|
||
# S3 bucket-level Public Access Block configuration | ||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
|
||
# Only allow uploads with specific KMS key | ||
attach_deny_incorrect_kms_key_sse = true | ||
allowed_kms_key_arn = aws_kms_key.objects.arn | ||
attach_deny_unencrypted_object_uploads = true | ||
|
||
versioning = { | ||
enabled = true | ||
} | ||
} |
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,73 @@ | ||
# Lambda Function | ||
output "lambda_function_arn" { | ||
description = "The ARN of the Lambda Function" | ||
value = module.lambda_function.lambda_function_arn | ||
} | ||
|
||
output "lambda_function_arn_static" { | ||
description = "The static ARN of the Lambda Function. Use this to avoid cycle errors between resources (e.g., Step Functions)" | ||
value = module.lambda_function.lambda_function_arn_static | ||
} | ||
|
||
output "lambda_function_invoke_arn" { | ||
description = "The Invoke ARN of the Lambda Function" | ||
value = module.lambda_function.lambda_function_invoke_arn | ||
} | ||
|
||
output "lambda_function_name" { | ||
description = "The name of the Lambda Function" | ||
value = module.lambda_function.lambda_function_name | ||
} | ||
|
||
output "lambda_function_qualified_arn" { | ||
description = "The ARN identifying your Lambda Function Version" | ||
value = module.lambda_function.lambda_function_qualified_arn | ||
} | ||
|
||
output "lambda_function_qualified_invoke_arn" { | ||
description = "The Invoke ARN identifying your Lambda Function Version" | ||
value = module.lambda_function.lambda_function_qualified_invoke_arn | ||
} | ||
|
||
output "lambda_function_version" { | ||
description = "Latest published version of Lambda Function" | ||
value = module.lambda_function.lambda_function_version | ||
} | ||
|
||
output "lambda_function_last_modified" { | ||
description = "The date Lambda Function resource was last modified" | ||
value = module.lambda_function.lambda_function_last_modified | ||
} | ||
|
||
output "lambda_function_source_code_hash" { | ||
description = "Base64-encoded representation of raw SHA-256 sum of the zip file" | ||
value = module.lambda_function.lambda_function_source_code_hash | ||
} | ||
|
||
output "lambda_function_source_code_size" { | ||
description = "The size in bytes of the function .zip file" | ||
value = module.lambda_function.lambda_function_source_code_size | ||
} | ||
|
||
# IAM Role | ||
output "lambda_role_arn" { | ||
description = "The ARN of the IAM role created for the Lambda Function" | ||
value = module.lambda_function.lambda_role_arn | ||
} | ||
|
||
output "lambda_role_name" { | ||
description = "The name of the IAM role created for the Lambda Function" | ||
value = module.lambda_function.lambda_role_name | ||
} | ||
|
||
# CloudWatch Log Group | ||
output "lambda_cloudwatch_log_group_arn" { | ||
description = "The ARN of the Cloudwatch Log Group" | ||
value = module.lambda_function.lambda_cloudwatch_log_group_arn | ||
} | ||
|
||
# Deployment package | ||
output "s3_object" { | ||
description = "The map with S3 object data of zip archive deployed (if deployment was from S3)" | ||
value = module.lambda_function.s3_object | ||
} |
Empty file.
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,14 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 4.63" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
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