Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Fix response for Lambda for ALB target group (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Aug 22, 2019
1 parent d99a840 commit b0581b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ gcloud app deploy --project=jira-to-slack appengine/app.yaml

### Lambda

You can deploy the application to AWS Lambda.
You can deploy the application to AWS Lambda and API Gateway.

```sh
# Run
Expand All @@ -113,6 +113,16 @@ make -C lambda deploy SAM_S3_BUCKET_NAME=YOUR_BUCKET_NAME

You need to create a S3 bucket in the same region before deploying.

If you want to deploy the application to AWS Lambda and ALB Target Group,
you need to change the request and response types as follows:

```sh
sed -i \
-e s/APIGatewayProxyRequest/ALBTargetGroupRequest/g \
-e s/APIGatewayProxyResponse/ALBTargetGroupResponse/g \
lambda/main.go
```


## How it works

Expand Down
11 changes: 8 additions & 3 deletions lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ func handleIndex(_ context.Context, r events.APIGatewayProxyRequest) (events.API
params, err := handlers.ParseWebhookParams(r.MultiValueQueryStringParameters)
if err != nil {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusBadRequest,
Body: err.Error(),
StatusCode: http.StatusOK,
Headers: map[string]string{"content-type": "text/plain"},
Body: fmt.Sprintf("OK\n%s", err.Error()),
}, nil
}
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Body: fmt.Sprintf("Parameter=%+v", params),
Body: fmt.Sprintf("OK\nreceived the parameters: %+v", params),
}, nil
}

Expand All @@ -32,13 +33,15 @@ func handleWebhook(ctx context.Context, r events.APIGatewayProxyRequest) (events
if err != nil {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusBadRequest,
Headers: map[string]string{"content-type": "text/plain"},
Body: err.Error(),
}, nil
}
var event jira.Event
if err := json.Unmarshal([]byte(r.Body), &event); err != nil {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusBadRequest,
Headers: map[string]string{"content-type": "text/plain"},
Body: fmt.Sprintf("could not decode json of response body: %s", err),
}, nil
}
Expand All @@ -53,11 +56,13 @@ func handleWebhook(ctx context.Context, r events.APIGatewayProxyRequest) (events
if err := u.Do(ctx, in); err != nil {
return events.APIGatewayProxyResponse{
StatusCode: http.StatusInternalServerError,
Headers: map[string]string{"content-type": "text/plain"},
Body: err.Error(),
}, nil
}
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Headers: map[string]string{"content-type": "text/plain"},
Body: "OK",
}, nil
}
Expand Down

0 comments on commit b0581b9

Please sign in to comment.