2
2
title: 'AWS Serving Dynamic HTML via API Gateway example in NodeJS'
3
3
description: 'This example illustrates how to hookup an API Gateway endpoint to a Lambda function to render HTML on a GET request.'
4
4
layout: Doc
5
- framework: v1
5
+ framework: v3
6
6
platform: AWS
7
7
language: nodeJS
8
8
priority: 10
9
9
authorLink: 'https://github.com/slate71'
10
10
authorName: 'Lukas Andersen'
11
11
authorAvatar: 'https://avatars0.githubusercontent.com/u/2078561?v=4&s=140'
12
12
-->
13
+
13
14
# Serving Dynamic HTML via API Gateway Example
14
15
15
16
This example illustrates how to hookup an API Gateway endpoint to a Lambda function to render HTML on a ` GET ` request.
@@ -27,7 +28,7 @@ Instead of returning the default `json` from a request, you can display custom d
27
28
const response = {
28
29
statusCode: 200 ,
29
30
headers: {
30
- ' Content-Type' : ' text/html' ,
31
+ " Content-Type" : " text/html" ,
31
32
},
32
33
body: html,
33
34
};
@@ -46,36 +47,21 @@ serverless deploy
46
47
The expected result should be similar to:
47
48
48
49
``` bash
49
- Serverless: Creating Stack...
50
- Serverless: Checking Stack create progress...
51
- .....
52
- Serverless: Stack create finished...
53
- Serverless: Packaging service...
54
- Serverless: Uploading CloudFormation file to S3...
55
- Serverless: Uploading service .zip file to S3 (1.01 KB)...
56
- Serverless: Updating Stack...
57
- Serverless: Checking Stack update progress...
58
- ...........................
59
- Serverless: Stack update finished...
60
-
61
- Service Information
62
- service: serve-dynamic-html-via-http-endpoint
63
- stage: dev
64
- region: us-east-1
65
- api keys:
66
- None
67
- endpoints:
68
- GET - https://nzkl1kas89.execute-api.us-east-1.amazonaws.com/dev/landing-page
50
+ Deploying serve-dynamic-html-via-http to stage dev (us-east-1)
51
+
52
+ ✔ Service deployed to stack serve-dynamic-html-via-http-dev (113s)
53
+
54
+ endpoint: GET - https://XXXXXXXXXXX.execute-api.us-east-1.amazonaws.com/landing-page
69
55
functions:
70
- serve-dynamic-html-via-http-endpoint-dev- landingPage: arn:aws:lambda:us-east-1:377024778620:function: serve-dynamic-html-via-http-endpoint- dev-landingPage
56
+ landingPage: serve-dynamic-html-via-http-dev-landingPage (466 B)
71
57
```
72
58
73
59
## Usage
74
60
75
61
You can now send an HTTP request directly to the endpoint using a tool like curl
76
62
77
63
``` bash
78
- curl https://nzkl1kas89 .execute-api.us-east-1.amazonaws.com/dev/landing-page? name=Nik%20Graf
64
+ curl https://XXXXXXXXXXX .execute-api.us-east-1.amazonaws.com/dev/landing-page? name=Nik%20Graf
79
65
```
80
66
81
67
The expected result should be similar to:
0 commit comments