Static Site Generation in Lambda with React Static

Overview

Reference Architecture

AWS Reference Infrastructure Diagram

Implementation

npm i -g react-static
react-static create
npm install --save-dev aws-sdk dotenv mime
node lambda/without-docker
import { tmpdir } from 'os'
// ...
const pathsBase = process.env.LAMBDA_USE_TMPDIR === 'true' ? tmpdir() + '/' : '';
// ...
export default {
// ...
paths: {
buildArtifacts: pathsBase + 'artifacts',
dist: pathsBase + 'dist',
temp: pathsBase + 'tmp',
},
// ...
}
FROM public.ecr.aws/lambda/nodejs:14
COPY . ${LAMBDA_TASK_ROOT}
RUN npm install
CMD ["lambda/index.handler"]
artifacts
dist
node_modules
tmp

.env

.git
.gitignore
docker build -t build-react-static-in-lambda .
docker run --env-file .env -p 9000:8080 build-react-static-in-lambda
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'

AWS

Test A
Test B
Test C

Lambda Costs

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store