- 浏览: 2552197 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
AMAZON and Lambda(3)Lambda with TypeScript/NodeJS
serverless framework
https://github.com/serverless/serverless
All examples
https://github.com/serverless/examples
Install the serverless tool
> sudo npm install serverless -g
Prepare the directory /Users/carl/work/typescript/node-typescript-lambda
Generate project from the template
> serverless create --template aws-nodejs
Serverless: Generating boilerplate...
_______ __
| _ .-----.----.--.--.-----.----| .-----.-----.-----.
| |___| -__| _| | | -__| _| | -__|__ --|__ --|
|____ |_____|__| \___/|_____|__| |__|_____|_____|_____|
| | | The Serverless Application Framework
| | serverless.com, v1.26.1
-------'
Serverless: Successfully generated boilerplate for template: "aws-nodejs"
Serverless: NOTE: Please update the "service" property in serverless.yml with your service name
I will have 2 files, handler.js and serverless.yml
Get and Setup the Credential
click my name and select “My Security Credential” —> “Users”—> “My Name”—> “Security Credentials”
Command will write the key and security in to ~/.aws/credentials
> serverless config credentials --provider aws --key AKIAJ4Vxxxxx --secret vEEJqNMXxxxxxxx
Change the service name in the YML file
service: node-ts-lambda
Deploy the lambda to server
> serverless deploy
Useful Plugins
serverless-offline and serverless-plugin-typescript
https://github.com/serverless/examples/tree/master/aws-node-typescript-rest-api-with-dynamodb
Serverless on Local
https://www.phodal.com/blog/serverless-architecture-development-serverless-offline-localhost-debug-test/
https://www.phodal.com/blog/serverless-developement-gui-lambda-api-gateway-dynamodb-create-restful-services/
Let’s make nodeJS working first
https://www.phodal.com/blog/serverless-architecture-development-serverless-offline-localhost-debug-test/
https://www.phodal.com/blog/serverless-developement-gui-lambda-api-gateway-dynamodb-create-restful-services/
Download the example project
> serverless install -u https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb -n aws-node-rest-api-with-dynamodb
Roughly read all codes in the sample in VisualStudio Code. It is straightforward.
Try to deploy the NodeJS one
> pwd
/Users/hluo/work/aws-node-rest-api-with-dynamodb
Npm install the uuid module
> npm install
Add serverless-offline Plugin
> yarn add --dev serverless-offline
> yarn add --dev serverless-dynamodb-local
Add Plugins in serverless.yml
plugins:
- serverless-offline
- serverless-dynamodb-local
custom:
dynamodb:
start:
port: 8000
inMemory: true
migrate: true
migration:
dir: offline/migrations
Set up the file
> cat offline/migrations/todos.json
{
"Table": {
"TableName": "serverless-rest-api-with-dynamodb-dev",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
}
}
Install the DB on local
> serverless dynamodb install
Start on Local
> serverless offline start
Dynamodb Local Started, Visit: http://localhost:8000/shell
Serverless: DynamoDB - created table aws-node-rest-api-with-dynamodb-dev
Serverless: Starting Offline: dev/us-east-1.
Serverless: Routes for create:
Serverless: POST /todos
Serverless: Routes for list:
Serverless: GET /todos
Serverless: Routes for get:
Serverless: GET /todos/{id}
Serverless: Routes for update:
Serverless: PUT /todos/{id}
Serverless: Routes for delete:
Serverless: DELETE /todos/{id}
Serverless: Offline listening on http://localhost:3000
Dynamodb local is here
http://localhost:8000/shell
When it runs, it throw exceptions:
{ ConfigError: Missing region in config
at Request.VALIDATE_REGION (/Users/hluo/work/aws-node-rest-api-with-dynamodb/node_modules/aws-sdk/lib/event_listeners.js:91:45)
at Request.callListeners (/Users/hluo/work/aws-node-rest-api-with-dynamodb/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
Because the NodeJS codes are still calling the remote DynamoDB, add file and change to call local
> cat todos/dynamodb.js
'use strict';
const AWS = require('aws-sdk'); // eslint-disable-line import/no-extraneous-dependencies
let options = {};
if (process.env.IS_OFFLINE) {
options = {
region: 'localhost',
endpoint: 'http://localhost:8000',
}
}
const client = new AWS.DynamoDB.DocumentClient(options);
module.exports = client;
//const dynamoDb = new AWS.DynamoDB.DocumentClient();
const dynamoDb = require('./dynamodb');
Start the Local Server Again
> serverless offline start
Post one Data
> curl -X POST -H "Content-Type:application/json" http://localhost:3000/todos --data '{ "text": "Learn Serverless" }'
{"id":"59c70760-27c0-11e8-a4bc-2bbab7cc4318","text":"Learn Serverless","checked":false,"createdAt":1521056772821,"updatedAt":1521056772821}
Refresh the page, we can see the data then.
http://localhost:3000/todos
We can also download the TypeScript Example
> serverless install -u https://github.com/serverless/examples/tree/master/aws-node-typescript-rest-api-with-dynamodb -n aws-node-typescript-rest-api-with-dynamodb
References:
https://blog.shovonhasan.com/deploying-a-typescript-node-aws-lambda-function-with-serverless/
https://gregshackles.com/getting-started-with-serverless-and-typescript/
https://www.jamestharpe.com/serverless-typescript-getting-started/
https://serverless.com/framework/docs/getting-started/
https://github.com/serverless/serverless
old notes
http://sillycat.iteye.com/blog/2409833
http://sillycat.iteye.com/blog/2410027
serverless framework
https://github.com/serverless/serverless
All examples
https://github.com/serverless/examples
Install the serverless tool
> sudo npm install serverless -g
Prepare the directory /Users/carl/work/typescript/node-typescript-lambda
Generate project from the template
> serverless create --template aws-nodejs
Serverless: Generating boilerplate...
_______ __
| _ .-----.----.--.--.-----.----| .-----.-----.-----.
| |___| -__| _| | | -__| _| | -__|__ --|__ --|
|____ |_____|__| \___/|_____|__| |__|_____|_____|_____|
| | | The Serverless Application Framework
| | serverless.com, v1.26.1
-------'
Serverless: Successfully generated boilerplate for template: "aws-nodejs"
Serverless: NOTE: Please update the "service" property in serverless.yml with your service name
I will have 2 files, handler.js and serverless.yml
Get and Setup the Credential
click my name and select “My Security Credential” —> “Users”—> “My Name”—> “Security Credentials”
Command will write the key and security in to ~/.aws/credentials
> serverless config credentials --provider aws --key AKIAJ4Vxxxxx --secret vEEJqNMXxxxxxxx
Change the service name in the YML file
service: node-ts-lambda
Deploy the lambda to server
> serverless deploy
Useful Plugins
serverless-offline and serverless-plugin-typescript
https://github.com/serverless/examples/tree/master/aws-node-typescript-rest-api-with-dynamodb
Serverless on Local
https://www.phodal.com/blog/serverless-architecture-development-serverless-offline-localhost-debug-test/
https://www.phodal.com/blog/serverless-developement-gui-lambda-api-gateway-dynamodb-create-restful-services/
Let’s make nodeJS working first
https://www.phodal.com/blog/serverless-architecture-development-serverless-offline-localhost-debug-test/
https://www.phodal.com/blog/serverless-developement-gui-lambda-api-gateway-dynamodb-create-restful-services/
Download the example project
> serverless install -u https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb -n aws-node-rest-api-with-dynamodb
Roughly read all codes in the sample in VisualStudio Code. It is straightforward.
Try to deploy the NodeJS one
> pwd
/Users/hluo/work/aws-node-rest-api-with-dynamodb
Npm install the uuid module
> npm install
Add serverless-offline Plugin
> yarn add --dev serverless-offline
> yarn add --dev serverless-dynamodb-local
Add Plugins in serverless.yml
plugins:
- serverless-offline
- serverless-dynamodb-local
custom:
dynamodb:
start:
port: 8000
inMemory: true
migrate: true
migration:
dir: offline/migrations
Set up the file
> cat offline/migrations/todos.json
{
"Table": {
"TableName": "serverless-rest-api-with-dynamodb-dev",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
}
}
}
Install the DB on local
> serverless dynamodb install
Start on Local
> serverless offline start
Dynamodb Local Started, Visit: http://localhost:8000/shell
Serverless: DynamoDB - created table aws-node-rest-api-with-dynamodb-dev
Serverless: Starting Offline: dev/us-east-1.
Serverless: Routes for create:
Serverless: POST /todos
Serverless: Routes for list:
Serverless: GET /todos
Serverless: Routes for get:
Serverless: GET /todos/{id}
Serverless: Routes for update:
Serverless: PUT /todos/{id}
Serverless: Routes for delete:
Serverless: DELETE /todos/{id}
Serverless: Offline listening on http://localhost:3000
Dynamodb local is here
http://localhost:8000/shell
When it runs, it throw exceptions:
{ ConfigError: Missing region in config
at Request.VALIDATE_REGION (/Users/hluo/work/aws-node-rest-api-with-dynamodb/node_modules/aws-sdk/lib/event_listeners.js:91:45)
at Request.callListeners (/Users/hluo/work/aws-node-rest-api-with-dynamodb/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
Because the NodeJS codes are still calling the remote DynamoDB, add file and change to call local
> cat todos/dynamodb.js
'use strict';
const AWS = require('aws-sdk'); // eslint-disable-line import/no-extraneous-dependencies
let options = {};
if (process.env.IS_OFFLINE) {
options = {
region: 'localhost',
endpoint: 'http://localhost:8000',
}
}
const client = new AWS.DynamoDB.DocumentClient(options);
module.exports = client;
//const dynamoDb = new AWS.DynamoDB.DocumentClient();
const dynamoDb = require('./dynamodb');
Start the Local Server Again
> serverless offline start
Post one Data
> curl -X POST -H "Content-Type:application/json" http://localhost:3000/todos --data '{ "text": "Learn Serverless" }'
{"id":"59c70760-27c0-11e8-a4bc-2bbab7cc4318","text":"Learn Serverless","checked":false,"createdAt":1521056772821,"updatedAt":1521056772821}
Refresh the page, we can see the data then.
http://localhost:3000/todos
We can also download the TypeScript Example
> serverless install -u https://github.com/serverless/examples/tree/master/aws-node-typescript-rest-api-with-dynamodb -n aws-node-typescript-rest-api-with-dynamodb
References:
https://blog.shovonhasan.com/deploying-a-typescript-node-aws-lambda-function-with-serverless/
https://gregshackles.com/getting-started-with-serverless-and-typescript/
https://www.jamestharpe.com/serverless-typescript-getting-started/
https://serverless.com/framework/docs/getting-started/
https://github.com/serverless/serverless
old notes
http://sillycat.iteye.com/blog/2409833
http://sillycat.iteye.com/blog/2410027
发表评论
-
Update Site will come soon
2021-06-02 04:10 1679I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 316I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 369Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 370Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 455VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 478NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ...
相关推荐
aws-lambda-typescript 构建管道,以使用打字稿轻松构建aws lambda函数。建立你的功能创建一个新的节点项目并用npm init它。 npm install --save-dev gulp aws-lambda-typescript 创建一个gulpfile.js文件将以下内容...
一个有思想的Typescript软件包,可帮助指定AWS Lambda处理程序,包括输入验证,错误处理和响应格式。 它是100%开源的,并根据许可。 快速开始 从NPM安装: npm install @enter-at/lambda-handlers 阿皮 状态码 ...
**PyPI 官网下载 | aws_cdk.aws_lambda_nodejs-1.63.0-py3-none-any.whl** 这个资源是Python开发者在AWS Cloud Development Kit (CDK)框架中使用的一个组件,用于构建和部署Node.js运行时的AWS Lambda函数。AWS ...
λ :dashing_away: aws-lambda-nodejs-esbuild 使用构造以构建Node.js AWS lambda。 目录 特征 零配置:开箱即用,无需安装任何其他软件包 支持具有转换限制的ESNext和TypeScript语法(请参阅Note ) 注意:默认...
"aws-cdk.aws-lambda-nodejs-1.42.1.tar.gz" 是一个从PyPI官网获取的压缩包,它包含了与Amazon Web Services (AWS) Cloud Development Kit (CDK)相关的组件,特别是针对AWS Lambda的Node.js支持。 **AWS Cloud ...
Alexa Skill在Typescript中使用AWS Lambda 这是一个基于的示例Alexa Skill处理程序。设置将安装为全局可用的软件包: $ npm install serverless -g 验证无服务器是否已正确安装: $ serverless -v 设置AWS凭证: 将...
AWS Lambda NodeJS自定义运行时在Node.js中实现的AWS Lambda运行时API。 该库可用于实现任何Node.js版本的自定义运行时Lambda层以Node.js为执行环境的容器运行时在本地测试您的Node.js lambda函数目标提供强大的...
AWS Lambda NodeJS运行时界面客户端 我们已开源了一组软件包,即运行时接口客户端(RIC),它们实现了Lambda ,使您可以无缝地将首选基础映像扩展为与Lambda兼容。 Lambda运行时界面客户端是一个轻量级的界面,允许...
Lambda经理 Lambda Builder是一个nodeJs cli,可用于创建由TsLinting,无服务器和npm配置组成的打字稿lambda项目。 cli还可以使用无服务器架构将lambda部署到aws或从aws移除。在部署Lambda之前,将根据tslint.json...
serverless-aws-nodejs-typescript 只是用于的最新,支持脱机使用。 先决条件 安装serverless CLI。 $ npm install -g serverless 完成后,从终端运行sls help确认安装。 用法 克隆存储库并安装依赖项。 $ git ...
- import {NodejsFunction} from '@aws-cdk/aws-lambda-nodejs';+ import {WatchableNodejsFunction} from 'cdk-watch';// ...- const lambda = new NodejsFunction(this, 'Lambda', {+ const lambda = new ...
Lambda + TypeScript + WebPack + Babel入门项目 该项目演示了使用以下技术: :AWS Lambda允许开发人员将可执行JavaScript代码包部署到AWS基础架构,并使它可执行,而不必担心管理服务器。 : webpack用于从利用ES6...
amazon-mws(亚马逊商城网络服务) 此 API 支持亚马逊市场网络服务 (MWS) 的标准 REST 样式 API,该 API 接受/返回 JSON 请求,这是 无需任何安装即可通过 API 进行验证。 印度市场: 美国市场: 其他市场: 它...
安装npm i lambaanpm i @types/aws-lambda -D示例项目看一下使用aws-nodejs-typescript模板创建的。指导控制器该库具有控制器的概念,类似于其他Web框架。 要创建控制器,请将@Controller()装饰器添加到类中。 使用...
serverless-bundle是一个插件,可以通过合理的默认值最佳地打包ES6或TypeScript Node.js Lambda函数,因此您不必维护自己的Webpack配置。 它在内部使用插件。 只有一个依赖 支持ES6和TypeScript 生成优化的软件包...
LambdaFS ...必须使用nodejs10.x或nodejs12.x AWS Lambda运行时,此程序包才能正常运行。 const lambdafs = require ( 'lambdafs' ) ; exports . handler = async ( event , context ) => { try { let f
Alexa Skill在Typescript中使用AWS Lambda 这是一个使用Typescript的Alexa技能的简单入门项目。先决条件Node.js 注册一个注册一个安装和设置安装安装依赖项$ npm install部署方式ASK CLI将为您创建技能和Lambda函数...
athena-client-一个用于nodejs和typescript的简单aws athena客户端 这是版本2.x文档。 1.x文档在 安装方式: npm install athena-client 使用范例 创建客户 var clientConfig = { bucketUri : 's3://xxxx' } var ...
通过这个项目,开发者将学习到如何配置和使用Serverless Framework,如何编写TypeScript代码并将其转换为能在AWS Lambda(或其他无服务器平台)上运行的JavaScript代码,以及如何管理依赖和部署流程。此外,还会涉及...
aws-lambda-sharp 安装依赖项 npm install 准备lambda 删除锋利的npm包 rm -rf node_modules/sharp/ ...docker run -v "$PWD":/var/task lambci/lambda:build-nodejs6.10 npm install 存档node_modules和index.js