https://gist.github.com/taion/1cfe1595a32b89ea4265679b38eee7b9
# Add sql connection parameters for production environment
./xc.config.json
"envs": {
"production": {
"db": [
{
"client": "mysql",
"connection": {
"host": "localhost",
"port": "3306",
"user": "root",
"password": "password",
"database": "sakila"
},
"meta": {
"tableName": "_evolutions",
"dbAlias": "primary"
}
}
],
"api" : {}
}
},
Open server/config/default.config.js
and set aws.lambda
to true and change other cloud serverless platform values as false
.
Install AWS cli & authenticate
Open serverless.yml
file and do the necessary changes.
npm run aws:lambda
npm install -g azure-functions-core-tools
npm run azure:deploy
npm run gcp:fn
Install Zeit now library and authenticate using email.
Add production
environment in config.xc.json
"envs": {
"production": {
"db": [
{
"client": "mysql",
"connection": {
"host": "localhost",
"port": "3306",
"user": "root",
"password": "password",
"database": "sakila"
},
"meta": {
"tableName": "_evolutions",
"dbAlias": "primary"
}
}
],
"api" : {}
}
},
npm run zeit:now
test
xc-examples-$autocannon -p 20 -c 50 -d 10 -m POST -H 'Content-Type: application/json' -b '{"query":"{ CountryList { country }}","variables":{}}' http://localhost:8080/graphql
Running 10s test @ http://localhost:8080/graphql
50 connections with 20 pipelining factor
┌─────────┬──────┬──────┬─────────┬─────────┬──────────┬───────────┬────────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼──────┼──────┼─────────┼─────────┼──────────┼───────────┼────────────┤
│ Latency │ 0 ms │ 0 ms │ 1009 ms │ 1729 ms │ 63.74 ms │ 288.24 ms │ 2185.45 ms │
└─────────┴──────┴──────┴─────────┴─────────┴──────────┴───────────┴────────────┘
┌───────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
│ Req/Sec │ 270 │ 270 │ 594 │ 1140 │ 712.9 │ 310.08 │ 270 │
├───────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
│ Bytes/Sec │ 235 kB │ 235 kB │ 516 kB │ 990 kB │ 619 kB │ 270 kB │ 235 kB │
└───────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┘
Req/Bytes counts sampled once per second.
7k requests in 10.09s, 6.19 MB read
xc-examples-$autocannon -p 20 -c 50 -d 10 -m POST -H 'Content-Type: application/json' -b '{"query":"{ CountryList { country\n CityList { city } }}","variables":{}}' http://localhost:8080/graphql
Running 10s test @ http://localhost:8080/graphql
50 connections with 20 pipelining factor
┌─────────┬──────┬──────┬─────────┬─────────┬──────────┬───────────┬────────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼──────┼──────┼─────────┼─────────┼──────────┼───────────┼────────────┤
│ Latency │ 0 ms │ 0 ms │ 1071 ms │ 1274 ms │ 59.26 ms │ 260.84 ms │ 2071.28 ms │
└─────────┴──────┴──────┴─────────┴─────────┴──────────┴───────────┴────────────┘
┌───────────┬─────┬──────┬─────────┬─────────┬─────────┬────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────┼──────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Req/Sec │ 0 │ 0 │ 910 │ 1000 │ 800 │ 295.93 │ 608 │
├───────────┼─────┼──────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Bytes/Sec │ 0 B │ 0 B │ 1.53 MB │ 1.68 MB │ 1.34 MB │ 497 kB │ 1.02 MB │
└───────────┴─────┴──────┴─────────┴─────────┴─────────┴────────┴─────────┘
Req/Bytes counts sampled once per second.
8k requests in 10.07s, 13.4 MB read
#Folder Structure Explained
$ aws iam create-role --role-name xc-rest-lambda --assume-role-policy-document '{"Version": "2012-10-17","Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}'
aws iam attach-role-policy --role-name xc-rest-lambda --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
npm run lambda:zip
npm run lambda:zip:win
aws lambda create-function --function-name xc-rest-serverless-app --zip-file fileb://lambda.zip --handler server/app.lambda --runtime nodejs12.x --role arn:aws:iam::249717198246:role/xc-rest-lambda --publish --timeout 180
aws lambda invoke --function-name xc-rest-serverless-app out --log-type Tail --query 'LogResult' --output text | base64 -D
API Gateway
to the xc-rest-serverless-app
using AWS web console.
rest api
gatewayANY
as method to accept all the HTTP method/{proxy+}
as resource to match all the sub-paths/{proxy+}
add ANY
as method to accept all the HTTP methodANY
. On the right side within Lambda Function
text field enter the lambda function name and save.fun
cli tool npm install @alicloud/fun -g
fun config
( https://www.alibabacloud.com/help/doc-detail/64204.htm )npm run ali:fn:compute
fun deploy
# xc-sakila