Skip to content

Commit b64057c

Browse files
committed
Added more runtime examples for Rust, Go, Java
1 parent a6ee11a commit b64057c

File tree

43 files changed

+921
-1380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+921
-1380
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.92.2
3+
rev: v1.94.1
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each
@@ -29,3 +29,5 @@ repos:
2929
- id: check-merge-conflict
3030
- id: end-of-file-fixer
3131
- id: trailing-whitespace
32+
- id: mixed-line-ending
33+
args: [--fix=lf]

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This Terraform module is the part of [serverless.tf framework](https://github.co
1616
## Features
1717

1818
- Build dependencies for your Lambda Function and Layer.
19-
- Support builds locally and in Docker (with or without SSH agent support for private builds).
19+
- Support builds locally and in Docker (with or without SSH agent support for private builds) for any runtime and architecture supported by AWS Lambda.
2020
- Create deployment package or deploy existing (previously built package) from local, from S3, from URL, or from AWS ECR repository.
2121
- Store deployment packages locally or in the S3 bucket.
2222
- Support almost all features of Lambda resources (function, layer, alias, etc.)
@@ -384,7 +384,7 @@ When `source_path` is set to a list of directories the content of each will be t
384384

385385
### Combine various options for extreme flexibility
386386

387-
This is the most complete way of creating a deployment package from multiple sources with multiple dependencies. This example is showing some of the available options (see [examples/build-package](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/build-package) for more):
387+
This is the most complete way of creating a deployment package from multiple sources with multiple dependencies. This example is showing some of the available options (see [examples/build-package](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/build-package) and [examples/runtimes](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/runtimes) for more):
388388

389389
```hcl
390390
source_path = [
@@ -643,6 +643,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo
643643
- [Complete](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/complete) - Create Lambda resources in various combinations with all supported features.
644644
- [Container Image](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/container-image) - Create a Docker image with a platform specified in the Dockerfile (using [docker provider](https://registry.terraform.io/providers/kreuzwerker/docker)), push it to AWS ECR, and create Lambda function from it.
645645
- [Build and Package](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/build-package) - Build and create deployment packages in various ways.
646+
- [Runtimes](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/build-package) - Build and create deployment packages for various runtimes (such as Rust, Go, Java).
646647
- [Alias](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/alias) - Create static and dynamic aliases in various ways.
647648
- [Deploy](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/deploy) - Complete end-to-end build/update/deploy process using AWS CodeDeploy.
648649
- [Async Invocations](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/async) - Create Lambda Function with async event configuration (with SQS, SNS, and EventBridge integration).
@@ -660,7 +661,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo
660661
- [1Mill/serverless-tf-examples](https://github.com/1Mill/serverless-tf-examples/tree/main/src)
661662

662663

663-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
664+
<!-- BEGIN_TF_DOCS -->
664665
## Requirements
665666

666667
| Name | Version |
@@ -904,7 +905,7 @@ No modules.
904905
| <a name="output_lambda_role_unique_id"></a> [lambda\_role\_unique\_id](#output\_lambda\_role\_unique\_id) | The unique id of the IAM role created for the Lambda Function |
905906
| <a name="output_local_filename"></a> [local\_filename](#output\_local\_filename) | The filename of zip archive deployed (if deployment was from local) |
906907
| <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) |
907-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
908+
<!-- END_TF_DOCS -->
908909

909910
## Development
910911

examples/alias/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ terraform apply
1414

1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

17-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
17+
<!-- BEGIN_TF_DOCS -->
1818
## Requirements
1919

2020
| Name | Version |
@@ -83,4 +83,4 @@ No inputs.
8383
| <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 |
8484
| <a name="output_local_filename"></a> [local\_filename](#output\_local\_filename) | The filename of zip archive deployed (if deployment was from local) |
8585
| <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) |
86-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
86+
<!-- END_TF_DOCS -->

examples/async/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ terraform apply
1414

1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

17-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
17+
<!-- BEGIN_TF_DOCS -->
1818
## Requirements
1919

2020
| Name | Version |
@@ -72,4 +72,4 @@ No inputs.
7272
| <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 |
7373
| <a name="output_local_filename"></a> [local\_filename](#output\_local\_filename) | The filename of zip archive deployed (if deployment was from local) |
7474
| <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) |
75-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
75+
<!-- END_TF_DOCS -->

examples/build-package/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Configuration in this directory creates deployment packages in a variety of combinations.
44

5+
Look into [Runtimes Examples](https://github.com/terraform-aws-modules/terraform-aws-lambda/tree/master/examples/runtimes) for more ways to build and deploy AWS Lambda Functions using supported runtimes (Rust, Go, Java).
6+
57
## Usage
68

79
To run this example you need to execute:
@@ -14,7 +16,7 @@ $ terraform apply
1416

1517
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1618

17-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
19+
<!-- BEGIN_TF_DOCS -->
1820
## Requirements
1921

2022
| Name | Version |
@@ -69,4 +71,4 @@ No inputs.
6971
## Outputs
7072

7173
No outputs.
72-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
74+
<!-- END_TF_DOCS -->

examples/code-signing/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ terraform apply
1414

1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

17-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
17+
<!-- BEGIN_TF_DOCS -->
1818
## Requirements
1919

2020
| Name | Version |
@@ -59,4 +59,4 @@ No inputs.
5959
| <a name="output_lambda_function_invoke_arn"></a> [lambda\_function\_invoke\_arn](#output\_lambda\_function\_invoke\_arn) | The Invoke ARN of the Lambda Function |
6060
| <a name="output_lambda_function_signing_job_arn"></a> [lambda\_function\_signing\_job\_arn](#output\_lambda\_function\_signing\_job\_arn) | ARN of the signing job |
6161
| <a name="output_lambda_function_signing_profile_version_arn"></a> [lambda\_function\_signing\_profile\_version\_arn](#output\_lambda\_function\_signing\_profile\_version\_arn) | ARN of the signing profile version |
62-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
62+
<!-- END_TF_DOCS -->

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $ terraform apply
1515

1616
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1717

18-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
18+
<!-- BEGIN_TF_DOCS -->
1919
## Requirements
2020

2121
| Name | Version |
@@ -92,4 +92,4 @@ No inputs.
9292
| <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 |
9393
| <a name="output_local_filename"></a> [local\_filename](#output\_local\_filename) | The filename of zip archive deployed (if deployment was from local) |
9494
| <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) |
95-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
95+
<!-- END_TF_DOCS -->

examples/container-image/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ terraform apply
1414

1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

17-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
17+
<!-- BEGIN_TF_DOCS -->
1818
## Requirements
1919

2020
| Name | Version |
@@ -79,4 +79,4 @@ No inputs.
7979
| <a name="output_lambda_layer_version"></a> [lambda\_layer\_version](#output\_lambda\_layer\_version) | The Lambda Layer version |
8080
| <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 |
8181
| <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 |
82-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
82+
<!-- END_TF_DOCS -->

examples/deploy/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $ terraform apply
1414

1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

17-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
17+
<!-- BEGIN_TF_DOCS -->
1818
## Requirements
1919

2020
| Name | Version |
@@ -63,4 +63,4 @@ No inputs.
6363
| <a name="output_codedeploy_iam_role_name"></a> [codedeploy\_iam\_role\_name](#output\_codedeploy\_iam\_role\_name) | Name of IAM role used by CodeDeploy |
6464
| <a name="output_deploy_script"></a> [deploy\_script](#output\_deploy\_script) | Path to a deployment script |
6565
| <a name="output_script"></a> [script](#output\_script) | Deployment script |
66-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
66+
<!-- END_TF_DOCS -->

examples/event-source-mapping/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,66 @@ $ terraform apply
1313
```
1414

1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+
17+
<!-- BEGIN_TF_DOCS -->
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.32 |
24+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
25+
26+
## Providers
27+
28+
| Name | Version |
29+
|------|---------|
30+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.32 |
31+
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
32+
33+
## Modules
34+
35+
| Name | Source | Version |
36+
|------|--------|---------|
37+
| <a name="module_lambda_function"></a> [lambda\_function](#module\_lambda\_function) | ../../ | n/a |
38+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
39+
40+
## Resources
41+
42+
| Name | Type |
43+
|------|------|
44+
| [aws_dynamodb_table.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table) | resource |
45+
| [aws_kinesis_stream.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kinesis_stream) | resource |
46+
| [aws_mq_broker.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/mq_broker) | resource |
47+
| [aws_secretsmanager_secret.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
48+
| [aws_secretsmanager_secret_version.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
49+
| [aws_sqs_queue.failure](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
50+
| [aws_sqs_queue.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
51+
| [random_password.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
52+
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
53+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
54+
| [aws_organizations_organization.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |
55+
56+
## Inputs
57+
58+
No inputs.
59+
60+
## Outputs
61+
62+
| Name | Description |
63+
|------|-------------|
64+
| <a name="output_lambda_event_source_mapping_function_arn"></a> [lambda\_event\_source\_mapping\_function\_arn](#output\_lambda\_event\_source\_mapping\_function\_arn) | The the ARN of the Lambda function the event source mapping is sending events to |
65+
| <a name="output_lambda_event_source_mapping_state"></a> [lambda\_event\_source\_mapping\_state](#output\_lambda\_event\_source\_mapping\_state) | The state of the event source mapping |
66+
| <a name="output_lambda_event_source_mapping_state_transition_reason"></a> [lambda\_event\_source\_mapping\_state\_transition\_reason](#output\_lambda\_event\_source\_mapping\_state\_transition\_reason) | The reason the event source mapping is in its current state |
67+
| <a name="output_lambda_event_source_mapping_uuid"></a> [lambda\_event\_source\_mapping\_uuid](#output\_lambda\_event\_source\_mapping\_uuid) | The UUID of the created event source mapping |
68+
| <a name="output_lambda_function_arn"></a> [lambda\_function\_arn](#output\_lambda\_function\_arn) | The ARN of the Lambda Function |
69+
| <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) |
70+
| <a name="output_lambda_function_invoke_arn"></a> [lambda\_function\_invoke\_arn](#output\_lambda\_function\_invoke\_arn) | The Invoke ARN of the Lambda Function |
71+
| <a name="output_lambda_function_kms_key_arn"></a> [lambda\_function\_kms\_key\_arn](#output\_lambda\_function\_kms\_key\_arn) | The ARN for the KMS encryption key of Lambda Function |
72+
| <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 |
73+
| <a name="output_lambda_function_name"></a> [lambda\_function\_name](#output\_lambda\_function\_name) | The name of the Lambda Function |
74+
| <a name="output_lambda_function_qualified_arn"></a> [lambda\_function\_qualified\_arn](#output\_lambda\_function\_qualified\_arn) | The ARN identifying your Lambda Function Version |
75+
| <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 |
76+
| <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 |
77+
| <a name="output_lambda_function_version"></a> [lambda\_function\_version](#output\_lambda\_function\_version) | Latest published version of Lambda Function |
78+
<!-- END_TF_DOCS -->
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go.sum
2+
bootstrap

examples/fixtures/runtimes/go/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module main
2+
3+
go 1.22.6
4+
5+
require github.com/aws/aws-lambda-go v1.47.0 // indirect

examples/fixtures/runtimes/go/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/aws/aws-lambda-go/lambda"
7+
)
8+
9+
type MyEvent struct {
10+
Name string `json:"name"`
11+
}
12+
13+
func HandleRequest(ctx context.Context, event *MyEvent) (*string, error) {
14+
if event == nil {
15+
return nil, fmt.Errorf("received nil event")
16+
}
17+
message := fmt.Sprintf("Hello %s! serverless.tf was here!", event.Name)
18+
return &message, nil
19+
}
20+
21+
func main() {
22+
lambda.Start(HandleRequest)
23+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gradle/
2+
build/
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
11+
implementation 'org.slf4j:slf4j-nop:2.0.6'
12+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
13+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
14+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
15+
}
16+
17+
test {
18+
useJUnitPlatform()
19+
}
20+
21+
// Using terraform-aws-lambda module, there is no need to make Zip archive by Gradle. Terraform AWS module will make it for you.
22+
// task buildZip(type: Zip) {
23+
// from compileJava
24+
// from processResources
25+
// into('lib') {
26+
// from configurations.runtimeClasspath
27+
// }
28+
// }
29+
30+
task copyFiles(type: Copy) {
31+
into("$buildDir/output")
32+
33+
from sourceSets.main.output
34+
35+
into('lib') {
36+
from configurations.runtimeClasspath
37+
}
38+
}
39+
40+
build.dependsOn copyFiles
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package example;
2+
3+
import com.amazonaws.services.lambda.runtime.Context;
4+
import com.amazonaws.services.lambda.runtime.LambdaLogger;
5+
import com.amazonaws.services.lambda.runtime.RequestHandler;
6+
7+
import java.util.Map;
8+
9+
// Handler value: example.Handler
10+
public class Handler implements RequestHandler<Map<String,String>, String>{
11+
12+
@Override
13+
public String handleRequest(Map<String,String> event, Context context)
14+
{
15+
LambdaLogger logger = context.getLogger();
16+
logger.log("EVENT TYPE: " + event.getClass());
17+
return "Hello from serverless.tf!!!";
18+
}
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

examples/fixtures/rust-app1/src/main.rs renamed to examples/fixtures/runtimes/rust/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async fn function_handler(event: Request) -> Result<Response<Body>, Error> {
1010
.query_string_parameters_ref()
1111
.and_then(|params| params.first("name"))
1212
.unwrap_or("world");
13-
let message = format!("Hello {who}, this is an AWS Lambda HTTP request");
13+
let message = format!("Hello {who}, this is an AWS Lambda HTTP request. serverless.tf was here!");
1414

1515
// Return something that implements IntoResponse.
1616
// It will be serialized to the right response event automatically by the runtime

examples/fixtures/rust-app1/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)