BAM! is a lightweight, serverless framework used to quickly build and deploy applications with Node.js and Amazon Web Services (AWS). We built BAM! to make it simpler for developers to launch AWS Lambdas that can be triggered by AWS API Gateway endpoints, which can be accomplished using the
We’d love for you to try out BAM!. Install the
bam-lambda package globally with npm, and give it a test ride!
One of the many uses for lambdas integrated with endpoints is to serve static web pages. As such, it only made sense for us to use the framework we had just built to deploy a site for the BAM! white paper, which discusses the development of the project.
To start, we issued the command
bam create bam, passing in the
--html flag to create a local directory named “bam”, which contains the templated lambda file
Instructional comments (such as those in the code above) can be included within any BAM! template by using the
--verbose flag when issuing the
create command. In addition to hints related to the specific template, these comments explain how to access query parameters, path parameters, and support different HTTP methods.
For local stylesheets, a
<script> tag was used.
AWS exposes files within the zipped directory of the deployed lambda using
readFile method with the
utf8 option (line 13). These strings can be stored in local variables such as
js (lines 17–23).
Once the contents of the files have been converted to strings, the
replacePlaceholder (lines 25–32) function can be used to, as its name suggests, replace the placeholders within the
html string with
<script> tags containing the appropriate text (lines 36–40). Setting the
content-type of the response headers to
text/html (line 9) will allow this string to be parsed as HTML and rendered correctly in a browser window.
Finally, we typed
bam deploy bam and deployed our site!