Owen Percoco
Owen Percoco

Reputation: 593

Using aws chalice to build a single page application?

Has anyone here ever worked with chalice? Its an aws tool for creating api's. I want to use it to create a single page application, but Im not sure how to actually serve html from it. I've seen videos where its explored, but I can't figure out how they actually built the thing. Anyone have any advice on where to go, how to start this?

Upvotes: 1

Views: 1642

Answers (2)

ddtraveller
ddtraveller

Reputation: 1232

Add Response from Chalice and the use it to set the response headers and you're g2g.

from chalice import Chalice, Response
return Response(template, status_code=200, headers={"Content-Type": "text/html", "Access-Control-Allow-Origin": "*"})

I read about it here;

https://medium.com/@tim_33529/creating-a-serverless-blog-with-chalice-bdc39b835f75

Upvotes: 2

bimsapi
bimsapi

Reputation: 5065

You wouldn't serve HTML from Chalice directly. It is explicitly designed to work in concert with AWS Lambda and API Gateway to serve dynamic, API-centric content. For the static parts of an SPA, you would use a web server (nginx or Apache) or S3 (with or without CloudFront).

Assuming you are interested in a purely "serverless" application model, I suggest looking into using the API Gateway "Proxy" resource type, forwarding to static resources on S3.

Worth noting that it's probably possible to serve HTML from Chalice, but from an architecture perspective, that's not the intent of the framework and you'd be swimming upstream to get all the capabilities and benefits from tools purpose-built for serving static traffic (full HTTP semantics w/ caching, conditional gets, etc)

Upvotes: 1

Related Questions