Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit 6c7a5a1

Browse files
basic hello world
1 parent 01a559c commit 6c7a5a1

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# nginx-lambda
22
Invoke lambda functions from NGINX.
3+
4+
# Contributing
5+
Run the code in docker-compose. Then go to http://localhost:8080/lambda to test.

nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ http {
1313
access_log on;
1414
listen 8080;
1515

16-
location /api {
16+
location /lambda {
1717
lambda arn:aws:lambda:us-east-1:397853141546:function:nginx-lambda:1.0;
1818
}
1919
}

ngx_http_lambda_module.c

+19-17
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ static ngx_int_t ngx_http_lambda_handler(ngx_http_request_t *r);
1414
*/
1515
static ngx_command_t ngx_http_lambda_commands[] = {
1616

17-
{ ngx_string("lambda"), /* directive */
18-
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, /* location context and takes 1 argument the lambda function ARN*/
17+
{
18+
ngx_string("lambda"), /* directive */
19+
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, /* location context and takes 1 argument the lambda function ARN */
1920
ngx_http_lambda, /* configuration setup function */
2021
0, /* No offset. Only one context is supported. */
2122
0, /* No offset when storing the module configuration on struct. */
22-
NULL},
23+
NULL
24+
},
2325

2426
ngx_null_command /* command termination */
2527
};
@@ -65,35 +67,35 @@ ngx_module_t ngx_http_lambda_module = {
6567
* @return
6668
* The status of the response generation.
6769
*/
68-
static ngx_int_t ngx_http_lambda_handler(ngx_http_request_t *r)
70+
static ngx_int_t ngx_http_lambda_handler(ngx_http_request_t *req)
6971
{
70-
ngx_buf_t *b;
72+
ngx_buf_t *buf;
7173
ngx_chain_t out;
7274

7375
/* Set the Content-Type header. */
74-
r->headers_out.content_type.len = sizeof("text/plain") - 1;
75-
r->headers_out.content_type.data = (u_char *) "text/plain";
76+
req->headers_out.content_type.len = sizeof("text/html") - 1;
77+
req->headers_out.content_type.data = (u_char *) "text/html";
7678

7779
/* Allocate a new buffer for sending out the reply. */
78-
b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
80+
buf = ngx_pcalloc(req->pool, sizeof(ngx_buf_t));
7981

8082
/* Insertion in the buffer chain. */
81-
out.buf = b;
83+
out.buf = buf;
8284
out.next = NULL; /* just one buffer */
8385

84-
b->pos = ngx_lambda; /* first position in memory of the data */
85-
b->last = ngx_lambda + sizeof(ngx_lambda); /* last position in memory of the data */
86-
b->memory = 1; /* content is in read-only memory */
87-
b->last_buf = 1; /* there will be no more buffers in the request */
86+
buf->pos = ngx_lambda; /* first position in memory of the data */
87+
buf->last = ngx_lambda + sizeof(ngx_lambda); /* last position in memory of the data */
88+
buf->memory = 1; /* content is in read-only memory */
89+
buf->last_buf = 1; /* there will be no more buffers in the request */
8890

8991
/* Sending the headers for the reply. */
90-
r->headers_out.status = NGX_HTTP_OK; /* 200 status code */
92+
req->headers_out.status = NGX_HTTP_OK; /* 200 status code */
9193
/* Get the content length of the body. */
92-
r->headers_out.content_length_n = sizeof(ngx_lambda);
93-
ngx_http_send_header(r); /* Send the headers */
94+
req->headers_out.content_length_n = sizeof(ngx_lambda);
95+
ngx_http_send_header(req); /* Send the headers */
9496

9597
/* Send the body, and return the status code of the output filter chain. */
96-
return ngx_http_output_filter(r, &out);
98+
return ngx_http_output_filter(req, &out);
9799
}
98100

99101
/**

0 commit comments

Comments
 (0)