12.10 g0v JS Workshop: Serverless React
筆記未完待補
- repo: https://github.com/hsin421/g0v-coding-workshop
- install https://nodejs.org/en/
- download zip
- unzip
- open terminal
- cd 'Downloads'
- cd 'g0v-coding-workshop-master'
- npm install
- npm run dev
- open browser
- go to localhost:8080
AWS Lambda
Choose Microservice from blueprints
In security: choose 'open', and next
type your lambda function name and 'create a new role.' Enter a role name.
Create lambda functino
Needed headers in lambda code:
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE',
'Access-Control-Allow-Origin': '*'
AWS API GATEWAY
To solve 'access-control-allow-origin problem'
'Enable CORS'
and add the above "access-control..." to your lambda code
AWS DynamoDB
create Table: choose a primary key (like userId) and a sort key
AWS S3
To deploy your site, use webpack to build your bundle by either 'node_modules/.bin/webpack' or 'npm run build'
Then upload your two files in ./build folder: index.html and bundle.js to a S3 bucket.
In the bucket settings, choose 'Enable static website hosting' and type index.html into the index document box.
Also, choose the two uploaded files, and in 'Actions' choose 'Make Public'
Results
Deployed address
http://g0v-example-workshop.s3-website-us-east-1.amazonaws.com/
Workshop Github source
https://github.com/hsin421/g0v-workshop-example-2