Skip to content

Commit af99733

Browse files
committed
2 parents 8e24ae3 + d918387 commit af99733

File tree

2 files changed

+34
-84
lines changed

2 files changed

+34
-84
lines changed
+21-45
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,29 @@
1-
const {
2-
PR_AUTHOR,
3-
PR_BODY,
4-
PR_NUMBER,
5-
IGNORE_AUTHORS,
6-
LABEL_PENDING_RELEASE,
7-
HANDLE_MAINTAINERS_TEAM,
8-
PR_IS_MERGED,
9-
} = require("./constants")
10-
111
module.exports = async ({github, context, core}) => {
12-
if (IGNORE_AUTHORS.includes(PR_AUTHOR)) {
13-
return core.notice("Author in IGNORE_AUTHORS list; skipping...")
14-
}
15-
16-
if (PR_IS_MERGED == "false") {
17-
return core.notice("Only merged PRs to avoid spam; skipping")
18-
}
2+
const prBody = context.payload.body;
3+
const prNumber = context.payload.number;
4+
const releaseLabel = process.env.RELEASE_LABEL;
5+
const maintainersTeam = process.env.MAINTAINERS_TEAM
196

207
const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;
218

22-
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
23-
24-
try {
25-
if (!isMatch) {
26-
core.setFailed(`Unable to find related issue for PR number ${PR_NUMBER}.\n\n Body details: ${PR_BODY}`);
27-
return await github.rest.issues.createComment({
28-
owner: context.repo.owner,
29-
repo: context.repo.repo,
30-
body: `${HANDLE_MAINTAINERS_TEAM} No related issues found. Please ensure '${LABEL_PENDING_RELEASE}' label is applied before releasing.`,
31-
issue_number: PR_NUMBER,
32-
});
33-
}
34-
} catch (error) {
35-
core.setFailed(`Unable to create comment on PR number ${PR_NUMBER}.\n\n Error details: ${error}`);
36-
throw new Error(error);
37-
}
38-
39-
const { groups: {issue} } = isMatch
40-
41-
try {
42-
core.info(`Auto-labeling related issue ${issue} for release`)
43-
return await github.rest.issues.addLabels({
44-
issue_number: issue,
9+
const isMatch = RELATED_ISSUE_REGEX.exec(prBody);
10+
if (!isMatch) {
11+
core.setFailed(`Unable to find related issue for PR number ${prNumber}.\n\n Body details: ${prBody}`);
12+
return await github.rest.issues.createComment({
4513
owner: context.repo.owner,
4614
repo: context.repo.repo,
47-
labels: [LABEL_PENDING_RELEASE]
48-
})
49-
} catch (error) {
50-
core.setFailed(`Is this issue number (${issue}) valid? Perhaps a discussion?`);
51-
throw new Error(error);
15+
body: `${maintainersTeam} No related issues found. Please ensure '${releaseLabel}' label is applied before releasing.`,
16+
issue_number: prNumber,
17+
});
5218
}
19+
20+
const { groups: {relatedIssueNumber} } = isMatch
21+
22+
core.info(`Auto-labeling related issue ${relatedIssueNumber} for release`)
23+
return await github.rest.issues.addLabels({
24+
issue_number: relatedIssueNumber,
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
labels: [releaseLabel]
28+
})
5329
}

docs/core/event_handler/api_gateway.md

+13-39
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ title: REST API
33
description: Core utility
44
---
55

6-
Event handler for Amazon API Gateway REST and HTTP APIs, Application Loader Balancer (ALB), and Lambda Function URLs.
6+
Event handler for Amazon API Gateway REST and HTTP APIs, and Application Loader Balancer (ALB).
77

88
## Key Features
99

10-
* Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API, ALB and Lambda Function URLs.
10+
* Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API and ALB
1111
* Support for CORS, binary and Gzip compression, Decimals JSON encoding and bring your own JSON serializer
1212
* Built-in integration with [Event Source Data Classes utilities](../../utilities/data_classes.md){target="_blank"} for self-documented event schema
1313

@@ -18,31 +18,23 @@ Event handler for Amazon API Gateway REST and HTTP APIs, Application Loader Bala
1818

1919
### Required resources
2020

21-
If you're using any API Gateway integration, you must have an existing [API Gateway Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html){target="_blank"} or [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html){target="_blank"} configured to invoke your Lambda function.
21+
You must have an existing [API Gateway Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html){target="_blank"} or [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html){target="_blank"} configured to invoke your Lambda function.
2222

23-
This is the sample infrastructure for API Gateway and Lambda Function URLs we are using for the examples in this documentation.
23+
This is the sample infrastructure for API Gateway we are using for the examples in this documentation.
2424

2525
???+ info "There is no additional permissions or dependencies required to use this utility."
2626

27-
=== "API Gateway SAM Template"
28-
29-
```yaml title="AWS Serverless Application Model (SAM) example"
30-
--8<-- "examples/event_handler_rest/sam/template.yaml"
31-
```
32-
33-
=== "Lambda Function URL SAM Template"
34-
35-
```yaml title="AWS Serverless Application Model (SAM) example"
36-
--8<-- "examples/event_handler_lambda_function_url/sam/template.yaml"
37-
```
27+
```yaml title="AWS Serverless Application Model (SAM) example"
28+
--8<-- "examples/event_handler_rest/sam/template.yaml"
29+
```
3830

3931
### Event Resolvers
4032

4133
Before you decorate your functions to handle a given path and HTTP method(s), you need to initialize a resolver.
4234

4335
A resolver will handle request resolution, including [one or more routers](#split-routes-with-router), and give you access to the current event via typed properties.
4436

45-
For resolvers, we provide: `APIGatewayRestResolver`, `APIGatewayHttpResolver`, `ALBResolver`, and `LambdaFunctionUrlResolver` .
37+
For resolvers, we provide: `APIGatewayRestResolver`, `APIGatewayHttpResolver`, and `ALBResolver`.
4638

4739
???+ info
4840
We will use `APIGatewayRestResolver` as the default across examples.
@@ -95,22 +87,6 @@ When using Amazon Application Load Balancer (ALB) to front your Lambda functions
9587
--8<-- "examples/event_handler_rest/src/getting_started_alb_api_resolver.py"
9688
```
9789

98-
#### Lambda Function URL
99-
100-
When using [AWS Lambda Function URL](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html), you can use `LambdaFunctionUrlResolver`.
101-
102-
=== "getting_started_lambda_function_url_resolver.py"
103-
104-
```python hl_lines="5 11" title="Using Lambda Function URL resolver"
105-
--8<-- "examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.py"
106-
```
107-
108-
=== "getting_started_lambda_function_url_resolver.json"
109-
110-
```json hl_lines="4-5" title="Example payload delivered to the handler"
111-
--8<-- "examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.json"
112-
```
113-
11490
### Dynamic routes
11591

11692
You can use `/todos/<todo_id>` to configure dynamic URL paths, where `<todo_id>` will be resolved at runtime.
@@ -222,7 +198,7 @@ You can use **`not_found`** decorator to override this behavior, and return a cu
222198

223199
You can use **`exception_handler`** decorator with any Python exception. This allows you to handle a common exception outside your route, for example validation errors.
224200

225-
```python hl_lines="13-14" title="Exception handling"
201+
```python hl_lines="14 15" title="Exception handling"
226202
--8<-- "examples/event_handler_rest/src/exception_handling.py"
227203
```
228204

@@ -291,7 +267,7 @@ This will ensure that CORS headers are always returned as part of the response w
291267

292268
#### Pre-flight
293269

294-
Pre-flight (OPTIONS) calls are typically handled at the API Gateway or Lambda Function URL level as per [our sample infrastructure](#required-resources), no Lambda integration is necessary. However, ALB expects you to handle pre-flight requests.
270+
Pre-flight (OPTIONS) calls are typically handled at the API Gateway level as per [our sample infrastructure](#required-resources), no Lambda integration necessary. However, ALB expects you to handle pre-flight requests.
295271

296272
For convenience, we automatically handle that for you as long as you [setup CORS in the constructor level](#cors).
297273

@@ -360,8 +336,6 @@ Like `compress` feature, the client must send the `Accept` header with the corre
360336
???+ warning
361337
This feature requires API Gateway to configure binary media types, see [our sample infrastructure](#required-resources) for reference.
362338

363-
???+ note
364-
Lambda Function URLs handle binary media types automatically.
365339
=== "binary_responses.py"
366340

367341
```python hl_lines="14 20"
@@ -403,7 +377,7 @@ This will enable full tracebacks errors in the response, print request and respo
403377

404378
### Custom serializer
405379

406-
You can instruct event handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
380+
You can instruct API Gateway handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
407381

408382
```python hl_lines="35 40" title="Using a custom JSON serializer for responses"
409383
--8<-- "examples/event_handler_rest/src/custom_serializer.py"
@@ -413,7 +387,7 @@ You can instruct event handler to use a custom serializer to best suit your need
413387

414388
As you grow the number of routes a given Lambda function should handle, it is natural to split routes into separate files to ease maintenance - That's where the `Router` feature is useful.
415389

416-
Let's assume you have `split_route.py` as your Lambda function entrypoint and routes in `split_route_module.py`. This is how you'd use the `Router` feature.
390+
Let's assume you have `app.py` as your Lambda function entrypoint and routes in `split_route_module.py`, this is how you'd use the `Router` feature.
417391

418392
=== "split_route_module.py"
419393

@@ -524,7 +498,7 @@ A micro function means that your final code artifact will be different to each f
524498

525499
**Downsides**
526500

527-
* **Upfront investment**. You need custom build tooling to bundle assets, including [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
501+
* **Upfront investment**. You need custom build tooling to bundle assets, including [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. `Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
528502
* Engineering discipline is necessary for both approaches. Micro-function approach however requires further attention in consistency as the number of functions grow, just like any distributed system.
529503
* **Harder to share code**. Shared code must be carefully evaluated to avoid unnecessary deployments when that changes. Equally, if shared code isn't a library,
530504
your development, building, deployment tooling need to accommodate the distinct layout.

0 commit comments

Comments
 (0)