Skip to content

Commit e561197

Browse files
committed
add good readme
1 parent cd1b29a commit e561197

File tree

1 file changed

+63
-21
lines changed

1 file changed

+63
-21
lines changed

README.md

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,77 @@
1-
# Terraform AWS Lambda
1+
# Eventbridge to API call
22

3-
_Template repository for creating a TypeScript AWS lambda function with Terraform_
3+
_An AWS Lambda for sending EventBridge events to API endpoint
44

5-
![Release](https://github.com/agendrix/terraform-aws-lambda/workflows/Release/badge.svg) ![Tests](https://github.com/agendrix/terraform-aws-lambda/workflows/Tests/badge.svg?branch=main)
5+
![Release](https://github.com/agendrix/eventbridge-slack-notifier/workflows/Release/badge.svg) ![Tests](https://github.com/agendrix/eventbridge-slack-notifier/workflows/Tests/badge.svg?branch=main)
66

7-
## How to use with Terraform
7+
## Description
88

9-
Add the module to your [Terraform](https://www.terraform.io/) project:
9+
The goal of this module is to send a POST to a specific API endpoint when an EventBridge [rule](https://docs.aws.amazon.com/eventbridge/latest/userguide/create-eventbridge-rule.html) is triggered.
1010

11-
```terraform
12-
module "terraform_aws_lambda" {
13-
source = "[email protected]:agendrix/terraform-aws-lambda.git//terraform?ref=v0.2.0"
14-
lambda_name = "my-typescript-lambda"
15-
role_arn = aws_iam_role.iam_for_lambda.role_arn
16-
}
11+
## Lambda payload
12+
13+
The lambda function payload is an object with the following type:
14+
```ts
15+
type Payload = {
16+
headers: {
17+
"Authorization": string,
18+
[key: string]: string
19+
};
20+
data: JSON;
21+
};
1722
```
23+
`headers`: Need at least the key `Authorization` to access the API
24+
25+
`data`: All the data you want to send to the API. Can be empty
26+
27+
## How to use with Terraform
28+
Add the module to your [Terraform](https://www.terraform.io/) project:
29+
30+
```HCL
31+
module "eventbridge_logger_opgenie" {
32+
source = "github.com/agendrix/eventbridge-to-make-api-call.git//terraform?ref=v0.1.2"
33+
sns_topic_to_notify_on_failure = <aws_sns_topic_arn>
34+
name = "Ressource Name"
1835
19-
See [Resource: aws_lambda_function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) for more information about the required `aws_iam_role`.
36+
api_config = {
37+
api_url = "<MY_API_URL>"
38+
api_key = "<MY_API_KEY_SECRET>"
39+
}
2040
21-
In order to be able to receive http requests to the lambda, you will need to hook it up with an AWS API Gateway.
22-
You can do so by following this guide: [Serverless Applications with AWS Lambda and API Gateway](https://learn.hashicorp.com/tutorials/terraform/lambda-api-gateway).
41+
event_pattern = jsonencode({
42+
source = ["aws.cloudwatch"]
43+
detail-type = ["CloudWatch Alarm State Change"]
44+
})
2345
24-
After applying the terraform plan, a dummy lambda will be available in the [AWS Lambda Console](https://console.aws.amazon.com/lambda/).
46+
input_transformer = {
47+
input_paths = {
48+
source = "$.source"
49+
time = "$.time"
50+
alarm = "$.detail.alarmName"
51+
}
52+
53+
input_template = <<EOF
54+
{
55+
"headers": {
56+
"Content-Type": "application/json",
57+
"Authorization": "Key "
58+
},
59+
"data": {
60+
"message": "My Message <source>",
61+
"description": "My Description: <time> <alarm>",
62+
}
63+
}
64+
EOF
65+
}
66+
}
67+
```
2568

26-
## Deploying a new version of the lambda
69+
### Resources:
2770

28-
- Make sure you have all the required [GitHub Actions secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets) for [`.github/workflows/release.yml`](.github/workflows/release.yml) to work.
29-
- Follow [CONTRIBUTING.md / Publish a new release](./CONTRIBUTING.md#publish-a-new-release) for deploying a new release.
71+
[How to create a rule pattern](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html)
3072

31-
---
73+
[Input transformer](https://docs.aws.amazon.com/eventbridge/latest/userguide/transform-input.html)
3274

33-
Your AWS lambda should now be available at https://console.aws.amazon.com/lambda/.
75+
[Input transformer Terraform](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target#input_transformer)
3476

35-
Logs from the lambda will be available in AWS CloudWatch `/aws/lambda/${yourLambdaName}` log group.
77+
[Common input transformer issues](https://docs.aws.amazon.com/eventbridge/latest/userguide/transform-input.html#transform-input-issues)

0 commit comments

Comments
 (0)