Skip to content

Commit 873fb75

Browse files
committed
chore: export values to SSM so those can be referenced from serverless
1 parent 090cd19 commit 873fb75

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

README.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ Terraform module that creates a Lambda function with zip packaging, IAM executio
1717
### Basic Usage with Template Generation
1818

1919
```hcl
20-
module "lambda_function" {
20+
module "lambda" {
2121
source = "git::https://github.com/ql4b/terraform-aws-lambda-function.git"
2222
23-
source_dir = "./src"
23+
source_dir = "../app/src"
24+
template_dir = "../app/src"
2425
create_templates = true
25-
template_dir = "./src"
2626
27-
context = {
28-
namespace = "myorg"
29-
name = "myfunction"
30-
}
27+
context = module.label.context
28+
attributes = ["lambda"]
3129
}
3230
```
3331

34-
This will automatically create `bootstrap`, `handler.sh`, and `Makefile` in your `./src` directory.
32+
This will automatically create `bootstrap`, `handler.sh`, and `Makefile` in your `../app/src` directory.
33+
34+
**Note:** This module integrates seamlessly with any existing Terraform setup. The example above shows integration with CloudPosse labeling, but you can use it standalone or with any naming convention.
3535

3636
## Advanced Usage
3737

@@ -64,6 +64,24 @@ module "lambda_function" {
6464
}
6565
```
6666

67+
## Integration with Existing Projects
68+
69+
This module is designed to plug into any existing Terraform setup:
70+
71+
```hcl
72+
# Add to your existing main.tf
73+
module "my_function" {
74+
source = "git::https://github.com/ql4b/terraform-aws-lambda-function.git"
75+
76+
source_dir = "./lambda-src"
77+
create_templates = true
78+
template_dir = "./lambda-src"
79+
80+
# Use your existing naming/tagging strategy
81+
context = var.context # or however you handle naming
82+
}
83+
```
84+
6785
## Template Generation
6886

6987
Set `create_templates = true` to automatically generate starter files:
@@ -132,16 +150,23 @@ terraform apply
132150
### 2. Set Function Name
133151

134152
```bash
153+
# If using the module directly
135154
export FUNCTION_NAME=$(terraform output -raw function_name)
155+
156+
# If using as a nested module (like in cloudless-minimal)
157+
export FUNCTION_NAME=$(tf output --json lambda | jq -r .function_name)
136158
```
137159

138160
### 3. Use the Generated Makefile
139161

140162
When `create_templates = true`, a `Makefile` is generated with deployment workflows:
141163

142164
```bash
143-
# Set function name
144-
export FUNCTION_NAME=$(terraform output -raw function_name)
165+
# Set function name (adjust based on your output structure)
166+
export FUNCTION_NAME=$(tf output --json lambda | jq -r .function_name)
167+
168+
# Navigate to your source directory
169+
cd app/src
145170

146171
# Deploy function code
147172
make deploy

main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,30 @@ resource "aws_lambda_function" "this" {
9898
aws_cloudwatch_log_group.lambda_logs,
9999
]
100100

101+
tags = module.this.tags
102+
}
103+
104+
# SSM parameters for Serverless integration
105+
resource "aws_ssm_parameter" "function_name" {
106+
name = "/${module.this.id}/function_name"
107+
type = "String"
108+
value = aws_lambda_function.this.function_name
109+
110+
tags = module.this.tags
111+
}
112+
113+
resource "aws_ssm_parameter" "function_arn" {
114+
name = "/${module.this.id}/function_arn"
115+
type = "String"
116+
value = aws_lambda_function.this.arn
117+
118+
tags = module.this.tags
119+
}
120+
121+
resource "aws_ssm_parameter" "invoke_arn" {
122+
name = "/${module.this.id}/invoke_arn"
123+
type = "String"
124+
value = aws_lambda_function.this.invoke_arn
125+
101126
tags = module.this.tags
102127
}

outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,14 @@ output "template_files" {
8080
handler = "${var.template_dir}/handler.sh"
8181
makefile = "${var.template_dir}/Makefile"
8282
} : {}
83+
}
84+
85+
# SSM parameter outputs
86+
output "ssm_parameters" {
87+
description = "SSM parameter names for Serverless integration"
88+
value = {
89+
function_name = aws_ssm_parameter.function_name.name
90+
function_arn = aws_ssm_parameter.function_arn.name
91+
invoke_arn = aws_ssm_parameter.invoke_arn.name
92+
}
8393
}

0 commit comments

Comments
 (0)