Skip to content

Commit 095645d

Browse files
authored
added support for using container images (#15)
* added support for using container images fixes #9 * cleanup * documentation
1 parent 4f1fca3 commit 095645d

File tree

33 files changed

+415
-138
lines changed

33 files changed

+415
-138
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.32.0
3+
rev: v1.45.0
44
hooks:
55
- id: terraform_fmt
66
- repo: git://github.com/pre-commit/pre-commit-hooks
7-
rev: v2.5.0
7+
rev: v3.3.0
88
hooks:
99
- id: check-merge-conflict
1010
- id: trailing-whitespace

README.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ should migrate to this module as a drop-in replacement for all provisions up to
2727

2828
The module can be used for all [runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) supported by AWS Lambda.
2929

30-
Deployment packages can be specified either directly as a local file (using the `filename` argument) or indirectly via Amazon S3 (using the `s3_bucket`, `s3_key` and `s3_object_versions` arguments), see [documentation](https://www.terraform.io/docs/providers/aws/r/lambda_function.html#specifying-the-deployment-package) for details.
30+
Deployment packages can be specified either directly as a local file (using the `filename` argument), indirectly via Amazon S3 (using the `s3_bucket`, `s3_key` and `s3_object_versions` arguments)
31+
or using [container images](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html) (using `image_uri` and `package_type` arguments),
32+
see [documentation](https://www.terraform.io/docs/providers/aws/r/lambda_function.html#specifying-the-deployment-package) for details.
3133

32-
**basic**
34+
**simple**
3335

34-
```terraform
36+
```hcl
3537
provider "aws" {
3638
region = "eu-west-1"
3739
}
@@ -47,9 +49,21 @@ module "lambda" {
4749
}
4850
```
4951

52+
**using container images**
53+
54+
```hcl
55+
module "lambda" {
56+
source = "moritzzimmer/lambda/aws"
57+
version = "5.6.0"
58+
function_name = "my-function"
59+
image_uri = "111111111111.dkr.ecr.eu-west-1.amazonaws.com/my-image"
60+
package_type = "Image"
61+
}
62+
```
63+
5064
**with event trigger**
5165

52-
```terraform
66+
```hcl
5367
module "lambda" {
5468
// see above
5569
@@ -62,7 +76,7 @@ module "lambda" {
6276

6377
**in a VPC**
6478

65-
```terraform
79+
```hcl
6680
module "lambda" {
6781
// see above
6882
@@ -75,7 +89,7 @@ module "lambda" {
7589

7690
**with access to parameter store**
7791

78-
```terraform
92+
```hcl
7993
module "lambda" {
8094
// see above
8195
@@ -87,7 +101,7 @@ module "lambda" {
87101

88102
**with log subscription (stream to ElasticSearch)**
89103

90-
```terraform
104+
```hcl
91105
module "lambda" {
92106
// see above
93107
@@ -97,6 +111,7 @@ module "lambda" {
97111

98112
### Examples
99113

114+
- [container-image](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/container-image)
100115
- [example-with-cloudwatch-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-cloudwatch-event)
101116
- [example-with-dynamodb-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-dynamodb-event)
102117
- [example-with-kinesis-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-kinesis-event)
@@ -105,7 +120,7 @@ module "lambda" {
105120
- [example-with-sqs-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-sqs-event)
106121
- [example-with-ssm-permissions](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-ssm-permissions)
107122
- [example-with-vpc](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-vpc)
108-
- [example-without-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-without-event)
123+
- [simple](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/simple)
109124

110125
### bootstrap with func
111126

@@ -127,12 +142,13 @@ MINOR, and PATCH versions on each release to indicate any incompatibilities.
127142
| Name | Version |
128143
|------|---------|
129144
| terraform | >= 0.12.0 |
145+
| aws | >= 3.19 |
130146

131147
## Providers
132148

133149
| Name | Version |
134150
|------|---------|
135-
| aws | n/a |
151+
| aws | >= 3.19 |
136152

137153
## Inputs
138154

@@ -141,25 +157,28 @@ MINOR, and PATCH versions on each release to indicate any incompatibilities.
141157
| description | Description of what your Lambda Function does. | `string` | `""` | no |
142158
| environment | Environment (e.g. env variables) configuration for the Lambda function enable you to dynamically pass settings to your function code and libraries | <pre>object({<br> variables = map(string)<br> })</pre> | `null` | no |
143159
| event | Event source configuration which triggers the Lambda function. Supported events: cloudwatch-scheduled-event, dynamodb, s3, sns | `map(string)` | `{}` | no |
144-
| filename | The path to the function's deployment package within the local filesystem. If defined, The s3\_-prefixed options cannot be used. | `string` | `""` | no |
160+
| filename | The path to the function's deployment package within the local filesystem. If defined, The s3\_-prefixed options and image\_uri cannot be used. | `string` | `null` | no |
145161
| function\_name | A unique name for your Lambda Function. | `any` | n/a | yes |
146-
| handler | The function entrypoint in your code. | `any` | n/a | yes |
162+
| handler | The function entrypoint in your code. | `string` | `""` | no |
163+
| image\_config | The Lambda OCI [image configurations](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function#image_config) block with three (optional) arguments:<br><br> - *entry\_point* - The ENTRYPOINT for the docker image (type `list(string)`).<br> - *command* - The CMD for the docker image (type `list(string)`).<br> - *working\_directory* - The working directory for the docker image (type `string`). | `any` | `{}` | no |
164+
| image\_uri | The ECR image URI containing the function's deployment package. Conflicts with filename, s3\_bucket, s3\_key, and s3\_object\_version. | `string` | `null` | no |
147165
| kms\_key\_arn | Amazon Resource Name (ARN) of the AWS Key Management Service (KMS) key that is used to encrypt environment variables. If this configuration is not provided when environment variables are in use, AWS Lambda uses a default service key. If this configuration is provided when environment variables are not in use, the AWS Lambda API does not save this configuration and Terraform will show a perpetual difference of adding the key. To fix the perpetual difference, remove this configuration. | `string` | `""` | no |
148166
| layers | List of Lambda Layer Version ARNs (maximum of 5) to attach to your Lambda Function. | `list(string)` | `[]` | no |
149-
| log\_retention\_in\_days | Specifies the number of days you want to retain log events in the specified log group. Defaults to 14. | `number` | `14` | no |
167+
| log\_retention\_in\_days | Specifies the number of days you want to retain log events in the specified log group. | `number` | `14` | no |
150168
| logfilter\_destination\_arn | The ARN of the destination to deliver matching log events to. Kinesis stream or Lambda function ARN. | `string` | `""` | no |
151-
| memory\_size | Amount of memory in MB your Lambda Function can use at runtime. Defaults to 128. | `number` | `128` | no |
152-
| publish | Whether to publish creation/change as new Lambda Function Version. Defaults to false. | `bool` | `false` | no |
153-
| reserved\_concurrent\_executions | The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. Defaults to Unreserved Concurrency Limits -1. | `string` | `"-1"` | no |
154-
| runtime | The runtime environment for the Lambda function you are uploading. | `any` | n/a | yes |
155-
| s3\_bucket | The S3 bucket location containing the function's deployment package. Conflicts with filename. This bucket must reside in the same AWS region where you are creating the Lambda function. | `string` | `""` | no |
156-
| s3\_key | The S3 key of an object containing the function's deployment package. Conflicts with filename. | `string` | `""` | no |
157-
| s3\_object\_version | The object version containing the function's deployment package. Conflicts with filename. | `string` | `""` | no |
169+
| memory\_size | Amount of memory in MB your Lambda Function can use at runtime. | `number` | `128` | no |
170+
| package\_type | The Lambda deployment package type. Valid values are Zip and Image. | `string` | `"Zip"` | no |
171+
| publish | Whether to publish creation/change as new Lambda Function Version. | `bool` | `false` | no |
172+
| reserved\_concurrent\_executions | The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations. | `string` | `"-1"` | no |
173+
| runtime | The runtime environment for the Lambda function you are uploading. | `string` | `""` | no |
174+
| s3\_bucket | The S3 bucket location containing the function's deployment package. Conflicts with filename and image\_uri. This bucket must reside in the same AWS region where you are creating the Lambda function. | `string` | `null` | no |
175+
| s3\_key | The S3 key of an object containing the function's deployment package. Conflicts with filename and image\_uri. | `string` | `null` | no |
176+
| s3\_object\_version | The object version containing the function's deployment package. Conflicts with filename and image\_uri. | `string` | `null` | no |
158177
| source\_code\_hash | Used to trigger updates. Must be set to a base64-encoded SHA256 hash of the package file specified with either filename or s3\_key. The usual way to set this is filebase64sha256('file.zip') where 'file.zip' is the local filename of the lambda function source archive. | `string` | `""` | no |
159178
| ssm | List of AWS Systems Manager Parameter Store parameter names. The IAM role of this Lambda function will be enhanced with read permissions for those parameters. Parameters must start with a forward slash and can be encrypted with the default KMS key. | <pre>object({<br> parameter_names = list(string)<br> })</pre> | `null` | no |
160179
| ssm\_parameter\_names | DEPRECATED: use `ssm` object instead. This variable will be removed in version 6 of this module. (List of AWS Systems Manager Parameter Store parameters this Lambda will have access to. In order to decrypt secure parameters, a kms\_key\_arn needs to be provided as well.) | `list` | `[]` | no |
161180
| tags | A mapping of tags to assign to the Lambda function and all resources supporting tags. | `map(string)` | `{}` | no |
162-
| timeout | The amount of time your Lambda Function has to run in seconds. Defaults to 3. | `number` | `3` | no |
181+
| timeout | The amount of time your Lambda Function has to run in seconds. | `number` | `3` | no |
163182
| tracing\_config\_mode | Tracing config mode of the Lambda function. Can be either PassThrough or Active. | `string` | `null` | no |
164183
| vpc\_config | Provide this to allow your function to access your VPC (if both 'subnet\_ids' and 'security\_group\_ids' are empty then vpc\_config is considered to be empty or unset, see https://docs.aws.amazon.com/lambda/latest/dg/vpc.html for details). | <pre>object({<br> security_group_ids = list(string)<br> subnet_ids = list(string)<br> })</pre> | `null` | no |
165184

docs/part1.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ should migrate to this module as a drop-in replacement for all provisions up to
2727

2828
The module can be used for all [runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) supported by AWS Lambda.
2929

30-
Deployment packages can be specified either directly as a local file (using the `filename` argument) or indirectly via Amazon S3 (using the `s3_bucket`, `s3_key` and `s3_object_versions` arguments), see [documentation](https://www.terraform.io/docs/providers/aws/r/lambda_function.html#specifying-the-deployment-package) for details.
30+
Deployment packages can be specified either directly as a local file (using the `filename` argument), indirectly via Amazon S3 (using the `s3_bucket`, `s3_key` and `s3_object_versions` arguments)
31+
or using [container images](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html) (using `image_uri` and `package_type` arguments),
32+
see [documentation](https://www.terraform.io/docs/providers/aws/r/lambda_function.html#specifying-the-deployment-package) for details.
3133

32-
**basic**
34+
**simple**
3335

34-
```terraform
36+
```hcl
3537
provider "aws" {
3638
region = "eu-west-1"
3739
}
@@ -47,9 +49,21 @@ module "lambda" {
4749
}
4850
```
4951

52+
**using container images**
53+
54+
```hcl
55+
module "lambda" {
56+
source = "moritzzimmer/lambda/aws"
57+
version = "5.6.0"
58+
function_name = "my-function"
59+
image_uri = "111111111111.dkr.ecr.eu-west-1.amazonaws.com/my-image"
60+
package_type = "Image"
61+
}
62+
```
63+
5064
**with event trigger**
5165

52-
```terraform
66+
```hcl
5367
module "lambda" {
5468
// see above
5569
@@ -62,7 +76,7 @@ module "lambda" {
6276

6377
**in a VPC**
6478

65-
```terraform
79+
```hcl
6680
module "lambda" {
6781
// see above
6882
@@ -75,7 +89,7 @@ module "lambda" {
7589

7690
**with access to parameter store**
7791

78-
```terraform
92+
```hcl
7993
module "lambda" {
8094
// see above
8195
@@ -87,7 +101,7 @@ module "lambda" {
87101

88102
**with log subscription (stream to ElasticSearch)**
89103

90-
```terraform
104+
```hcl
91105
module "lambda" {
92106
// see above
93107
@@ -97,6 +111,7 @@ module "lambda" {
97111

98112
### Examples
99113

114+
- [container-image](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/container-image)
100115
- [example-with-cloudwatch-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-cloudwatch-event)
101116
- [example-with-dynamodb-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-dynamodb-event)
102117
- [example-with-kinesis-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-kinesis-event)
@@ -105,7 +120,7 @@ module "lambda" {
105120
- [example-with-sqs-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-sqs-event)
106121
- [example-with-ssm-permissions](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-ssm-permissions)
107122
- [example-with-vpc](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-with-vpc)
108-
- [example-without-event](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/example-without-event)
123+
- [simple](https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/simple)
109124

110125
### bootstrap with func
111126

0 commit comments

Comments
 (0)