-
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for creating lambdas that use Container Images (#80)
- Loading branch information
1 parent
ff0a5dd
commit 9f9930c
Showing
24 changed files
with
313 additions
and
18 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*.tfstate | ||
*.tfvars | ||
*.tfplan | ||
.terraform.lock.hcl | ||
|
||
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
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
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
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,61 @@ | ||
# AWS Lambda launched from Docker Container Image example | ||
|
||
Configuration in this directory creates AWS Lambda Function deployed with a Container Image. | ||
|
||
## 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 | | ||
|------|---------| | ||
| terraform | >= 0.12.6 | | ||
| aws | >= 2.67 | | ||
| random | >= 2 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| aws | >= 2.67 | | ||
| random | >= 2 | | ||
|
||
## Inputs | ||
|
||
No input. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| lambda\_cloudwatch\_log\_group\_arn | The ARN of the Cloudwatch Log Group | | ||
| lambda\_role\_arn | The ARN of the IAM role created for the Lambda Function | | ||
| lambda\_role\_name | The name of the IAM role created for the Lambda Function | | ||
| local\_filename | The filename of zip archive deployed (if deployment was from local) | | ||
| s3\_object | The map with S3 object data of zip archive deployed (if deployment was from S3) | | ||
| this\_lambda\_function\_arn | The ARN of the Lambda Function | | ||
| this\_lambda\_function\_invoke\_arn | The Invoke ARN of the Lambda Function | | ||
| this\_lambda\_function\_kms\_key\_arn | The ARN for the KMS encryption key of Lambda Function | | ||
| this\_lambda\_function\_last\_modified | The date Lambda Function resource was last modified | | ||
| this\_lambda\_function\_name | The name of the Lambda Function | | ||
| this\_lambda\_function\_qualified\_arn | The ARN identifying your Lambda Function Version | | ||
| this\_lambda\_function\_source\_code\_hash | Base64-encoded representation of raw SHA-256 sum of the zip file | | ||
| this\_lambda\_function\_source\_code\_size | The size in bytes of the function .zip file | | ||
| this\_lambda\_function\_version | Latest published version of Lambda Function | | ||
| this\_lambda\_layer\_arn | The ARN of the Lambda Layer with version | | ||
| this\_lambda\_layer\_created\_date | The date Lambda Layer resource was created | | ||
| this\_lambda\_layer\_layer\_arn | The ARN of the Lambda Layer without version | | ||
| this\_lambda\_layer\_source\_code\_size | The size in bytes of the Lambda Layer .zip file | | ||
| this\_lambda\_layer\_version | The Lambda Layer version | | ||
|
||
<!-- 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,2 @@ | ||
FROM scratch | ||
COPY empty /empty |
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 @@ | ||
# 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,65 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
|
||
# Make it faster by skipping something | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
module "lambda_function_from_container_image" { | ||
source = "../../" | ||
|
||
function_name = "${random_pet.this.id}-lambda-from-container-image" | ||
description = "My awesome lambda function from container image" | ||
|
||
create_package = false | ||
|
||
################## | ||
# Container Image | ||
################## | ||
image_uri = docker_registry_image.app.name | ||
package_type = "Image" | ||
} | ||
|
||
################# | ||
# ECR Repository | ||
################# | ||
resource "aws_ecr_repository" "this" { | ||
name = random_pet.this.id | ||
} | ||
|
||
############################################### | ||
# Create Docker Image and push to ECR registry | ||
############################################### | ||
|
||
data "aws_caller_identity" "this" {} | ||
data "aws_region" "current" {} | ||
data "aws_ecr_authorization_token" "token" {} | ||
|
||
locals { | ||
ecr_address = format("%v.dkr.ecr.%v.amazonaws.com", data.aws_caller_identity.this.account_id, data.aws_region.current.name) | ||
ecr_image = format("%v/%v:%v", local.ecr_address, aws_ecr_repository.this.id, "1.0") | ||
} | ||
|
||
provider "docker" { | ||
registry_auth { | ||
address = local.ecr_address | ||
username = data.aws_ecr_authorization_token.token.user_name | ||
password = data.aws_ecr_authorization_token.token.password | ||
} | ||
} | ||
|
||
resource "docker_registry_image" "app" { | ||
name = local.ecr_image | ||
|
||
build { | ||
context = "context" | ||
} | ||
} |
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,88 @@ | ||
# Lambda Function | ||
output "this_lambda_function_arn" { | ||
description = "The ARN of the Lambda Function" | ||
value = module.lambda_function_from_container_image.this_lambda_function_arn | ||
} | ||
|
||
output "this_lambda_function_invoke_arn" { | ||
description = "The Invoke ARN of the Lambda Function" | ||
value = module.lambda_function_from_container_image.this_lambda_function_invoke_arn | ||
} | ||
|
||
output "this_lambda_function_name" { | ||
description = "The name of the Lambda Function" | ||
value = module.lambda_function_from_container_image.this_lambda_function_name | ||
} | ||
|
||
output "this_lambda_function_qualified_arn" { | ||
description = "The ARN identifying your Lambda Function Version" | ||
value = module.lambda_function_from_container_image.this_lambda_function_qualified_arn | ||
} | ||
|
||
output "this_lambda_function_version" { | ||
description = "Latest published version of Lambda Function" | ||
value = module.lambda_function_from_container_image.this_lambda_function_version | ||
} | ||
|
||
output "this_lambda_function_last_modified" { | ||
description = "The date Lambda Function resource was last modified" | ||
value = module.lambda_function_from_container_image.this_lambda_function_last_modified | ||
} | ||
|
||
output "this_lambda_function_kms_key_arn" { | ||
description = "The ARN for the KMS encryption key of Lambda Function" | ||
value = module.lambda_function_from_container_image.this_lambda_function_kms_key_arn | ||
} | ||
|
||
output "this_lambda_function_source_code_hash" { | ||
description = "Base64-encoded representation of raw SHA-256 sum of the zip file" | ||
value = module.lambda_function_from_container_image.this_lambda_function_source_code_hash | ||
} | ||
|
||
output "this_lambda_function_source_code_size" { | ||
description = "The size in bytes of the function .zip file" | ||
value = module.lambda_function_from_container_image.this_lambda_function_source_code_size | ||
} | ||
|
||
# Lambda Layer | ||
output "this_lambda_layer_arn" { | ||
description = "The ARN of the Lambda Layer with version" | ||
value = module.lambda_function_from_container_image.this_lambda_layer_arn | ||
} | ||
|
||
output "this_lambda_layer_layer_arn" { | ||
description = "The ARN of the Lambda Layer without version" | ||
value = module.lambda_function_from_container_image.this_lambda_layer_layer_arn | ||
} | ||
|
||
output "this_lambda_layer_created_date" { | ||
description = "The date Lambda Layer resource was created" | ||
value = module.lambda_function_from_container_image.this_lambda_layer_created_date | ||
} | ||
|
||
output "this_lambda_layer_source_code_size" { | ||
description = "The size in bytes of the Lambda Layer .zip file" | ||
value = module.lambda_function_from_container_image.this_lambda_layer_source_code_size | ||
} | ||
|
||
output "this_lambda_layer_version" { | ||
description = "The Lambda Layer version" | ||
value = module.lambda_function_from_container_image.this_lambda_layer_version | ||
} | ||
|
||
# IAM Role | ||
output "lambda_role_arn" { | ||
description = "The ARN of the IAM role created for the Lambda Function" | ||
value = module.lambda_function_from_container_image.lambda_role_arn | ||
} | ||
|
||
output "lambda_role_name" { | ||
description = "The name of the IAM role created for the Lambda Function" | ||
value = module.lambda_function_from_container_image.lambda_role_name | ||
} | ||
|
||
# CloudWatch Log Group | ||
output "lambda_cloudwatch_log_group_arn" { | ||
description = "The ARN of the Cloudwatch Log Group" | ||
value = module.lambda_function_from_container_image.lambda_cloudwatch_log_group_arn | ||
} |
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,13 @@ | ||
terraform { | ||
required_version = ">= 0.12.6" | ||
|
||
required_providers { | ||
aws = ">= 3.19" | ||
random = ">= 2" | ||
|
||
docker = { | ||
source = "kreuzwerker/docker" | ||
version = ">= 2.8.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
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
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
Oops, something went wrong.