我正在使用 VS Code 开发 AWS Lambda 函数,我开始使用无服务器框架和无服务器离线库,但是,我无法使用 VS Code 的调试模式在本地调试代码。
我指的是许多网站,以下是其中之一: https://medium.com/@OneMuppet_/debugging-lambada-functions-locally-in-vscode-with-actual-break-points-deee6235f590
我的项目结构如下:
Package.json
:
launch.json
:
当我开始调试时出现以下错误:
有人可以指导一下正确的配置吗?
javascript node.js visual-studio-code serverless-framework serverless-offline
我已使用 CloudFormation 语法在 API 网关资源上声明了一个 HTTP 代理方法(详细信息请参阅之前的文章。)
\n\n我正在尝试附加一个类型为“Request”的自定义授权者,它使用现有的 AWS Lambda 函数。无服务器文档有一个使用 CloudFormation 设置自定义授权者的不错示例。同时,无服务器离线 显然支持(源)请求范围的自定义授权者。
\n\n在创建以下无服务器模板时,我仔细交叉引用了AWS::ApiGateway::Resource和AWS::ApiGateway::Authorizer的相关 AWS CloudFormation 文档以及相关的无服务器文档。但到目前为止,我没有从无服务器离线获得预期的输出或行为获得预期的输出或行为。
\n\n当我启动以下无服务器配置时,不会为我的资源加载授权者。我没有看到我的serverless.yml
文件中有什么错误或缺失。你有什么建议吗?提前致谢!
\xe2\x9e\x9c serverless-offline-attempt git:(master) \xe2\x9c\x97 npm start\n\n> @ start /Users/freen/src/apig/serverless-offline-attempt\n> ./node_modules/serverless/bin/serverless offline\n\nServerless: Starting Offline: dev/us-east-1.\n\nServerless: Routes defined in resources:\nServerless: ANY /upstream/{proxy*} -> http://upstream.company.cool/{proxy}\n\nServerless: Offline listening on http://localhost:3000\n
Run Code Online (Sandbox Code Playgroud)\n\nserverless.yml
以下模板文件包含 APIG 资源和授权者配置。
\n\n\xe2\x9e\x9c serverless-offline-attempt git:(master) \xe2\x9c\x97 npm start\n\n> @ start …
Run Code Online (Sandbox Code Playgroud) aws-lambda aws-api-gateway serverless-framework serverless serverless-offline
我正在运行我的 nodejs 代码并安装了无服务器(npm i -g serverless)但是在使用命令运行它时sls offline start --CacheInvalidations
我收到错误:-
无服务器错误 -------------------------------
未找到无服务器命令“离线”。您指的是 “config” 吗? 运行“无服务器帮助”以获取所有可用命令的列表。
得到支持 - - - - - - - - - - - - - - - - - - - - - -
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Run Code Online (Sandbox Code Playgroud)
您的环境信息 ---------------------------
Operating System: linux
Node Version: 12.18.2
Framework Version: 1.79.0
Plugin Version: 3.7.1
SDK Version: 2.3.1
Components Version: 2.34.6
Run Code Online (Sandbox Code Playgroud) 我按照 webpack4 示例来设置配置:https : //github.com/serverless-heaven/serverless-webpack/tree/master/examples/babel-webpack-4 因为我收到错误“找不到模块源-地图支持/注册”。
我已经研究了已经创建的问题:
https://github.com/serverless-heaven/serverless-webpack/issues/357
https://github.com/serverless-heaven/serverless-webpack/issues/228
现在我的配置是:
.babelrc{
"comments": false,
"sourceMaps": "both",
"presets": ["env","stage-2"],
"plugins": ["source-map-support"]
}
Run Code Online (Sandbox Code Playgroud)
webpack.config.js:
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const slsw = require('serverless-webpack');
module.exports = {
entry: slsw.lib.entries,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
output: {
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
sourceMapFilename: '[file].map',
},
optimization: {
// We no not want to minimize our code.
minimize: false,
},
performance: {
// Turn off size warnings for …
Run Code Online (Sandbox Code Playgroud) node.js webpack serverless serverless-webpack-plugin serverless-offline
我正在尝试找出一种使用无服务器框架和无服务器离线在 VS Code 中调试 AWS python lambdas 的方法。我已经到了可以在 VS Code 中运行 lambdas 的地步,但我无法设置断点。我不确定这是否可能,但从我读过的内容来看,它似乎是可能的。如果有人可以提供帮助,将不胜感激。
这是我当前的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"debug"
],
"port": 9229,
}
]
}
Run Code Online (Sandbox Code Playgroud)
package.json 的脚本部分如下:
"scripts": {
"start": "./node_modules/.bin/serverless offline -s dev",
"debug": "export SLS_DEBUG=* && node --inspect ./node_modules/.bin/serverless offline -s dev"
}
Run Code Online (Sandbox Code Playgroud)
同样,此设置有效。我只是希望能够在我的 .py 文件中设置断点。当我将鼠标悬停在左侧装订线中的断点上时,它们会变灰并显示Breakpoint ignored because generated code not found (source map problem?).
我不知道如何解决这个问题,因为 python 文件没有源映射。我尝试将outfile
launch.json的字段设置为python 文件本身,但这显然不起作用。
在此先感谢那些能够提供帮助的人。 …
python debugging amazon-web-services serverless-framework serverless-offline
我正在构建一个 AWS Lambda 函数并尝试为其编写一些集成测试。Lambda 函数使用无服务器离线插件在本地运行,并且只需接收带有一些查询参数的 GET 请求。我使用 Jest 和 Supertest 编写集成测试,如下所示:
import request from 'supertest';
describe('User position handler', () => {
it('should return history', () => {
const server = request('http://0.0.0.0:4000');
return server
.get(`/local/position?type=month&period=3`)
.expect(200)
.expect((response) => {
console.log('RESPONSE', response);
expect(response.body).toHaveLength(3);
});
});
});
Run Code Online (Sandbox Code Playgroud)
问题是,当我使用收集覆盖率选项运行 Jest 时,通过 Supertest 发送的请求到达的代码不会在指标中计算。运行jest --collectCoverage
结果是:
问题是,我知道,例如,infra/handlers/user-position.ts
正在达到并覆盖超过 0% 的语句,但覆盖率指标并未按预期显示。另外,我知道user-monthly-position.service.impl.ts
在流程的某个点已经达到了这一点,因为该服务负责从外部服务返回数据,并且 Supertest 的响应正在返回数据。绿线来自单元测试覆盖的文件,这些文件仅使用 Jest(显然不是 Supertest)
我知道当将 Supertest 与 Express 框架一起使用时,我可以传递 Express 应用程序的实例。到request
函数。这样我认为 Jest 可以“检查”或“检测”函数调用堆栈来测量覆盖率(下面的代码示例)。但是如何传递正在运行的serverless-offline
Lambda 的 URL …
amazon-web-services supertest jestjs serverless-framework serverless-offline
我在使用时无法热重载serverless offline start
。
这是我的 serverless.yml 文件
service: function-with-environment-variables
frameworkVersion: ">=3.0.0 <4.0.0"
provider:
name: aws
runtime: nodejs16.x
plugins:
- serverless-offline
functions:
register:
handler: handler.register
events:
- http:
path: /register
method: post
login:
handler: handler.login
events:
- http:
path: /login
method: post
verify:
handler: handler.verify
events:
- http:
path: /verify
method: post
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用sls offline start
仍然面临同样的错误。
这是输出serverless --version
`从node_modules运行“无服务器”框架核心:3.24.1(本地)3.24.1(全局)插件:6.2.2 SDK:4.3.2
我想serverless offline
使用指向 Docker 映像的 Lambda 函数来运行。
当我尝试运行时serverless offline
,我只是收到:
Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
* hello-function: sample-app3-dev-hello-function
Run Code Online (Sandbox Code Playgroud)
如果我尝试访问http://localhost:3002/hello,会返回404错误
serverless.yml
Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
* hello-function: sample-app3-dev-hello-function
Run Code Online (Sandbox Code Playgroud)
app/myfunction.py
service: sample-app3
frameworkVersion: '3'
plugins:
- serverless-offline
provider:
name: aws
ecr:
images:
sampleapp3image:
path: ./app/
platform: linux/amd64
functions:
hello-function:
image:
name: sampleapp3image
events:
- httpApi:
path: /hello
method: GET …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用无服务器离线在本地开发/模拟我的 API 网关。我的 API 网关自由地使用了HTTP 代理集成。生产资源如下所示:
我根据一些文档和讨论创建了一个无服务器离线配置,这些文档和讨论表明可以使用 Cloud Formation 配置定义 HTTP 代理集成:
我已根据我的目的改编了上述两个配置示例,请参见下文。
有什么提示,我可能在这里做错了什么?
plugins:
- serverless-offline
service: company-apig
provider:
name: aws
stage: dev
runtime: python2.7
resources:
Resources:
# Parent APIG RestApi
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: company-apig
Description: 'The main entry point of the APIG'
# Resource /endpoint
EndpointResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
PathPart: 'endpoint' …
Run Code Online (Sandbox Code Playgroud) aws-api-gateway serverless-framework serverless serverless-offline
我正在尝试使用 NodeJS、AWS Lambda、API Gateway、RDS 和 PostgreSQL 部署无服务器 REST API。
到目前为止,我已经成功设置了 PostgreSQL RDS,在开始编写函数来处理对数据库的请求之前,我认为最好先在本地测试一个小函数以检查请求是否得到正确处理。
所以在项目的根目录下,我安装了 serverless-offline:
npm install serverless-offline
它在安装类型时发出了几个警告:
npm WARN 已弃用 @hapi/pez@4.1.2:此版本已弃用,不再支持或维护
(如果这些信息无关紧要,我很抱歉,我是新手,不知道什么是重要的,什么不重要。)
然后我配置了我的serverless.yml:
service: serverless-node-postgres-rds-rest-api
app: serverless-app
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
plugins:
- serverless-offline
configValidationMode: error
functions:
hello:
handler: handler.hello
events:
- httpApi:
path: hello
method: get
Run Code Online (Sandbox Code Playgroud)
这是handler.js:
'use strict';
module.exports.hello = async (event) => {
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'Go Serverless v1.0! Your function executed …
Run Code Online (Sandbox Code Playgroud) serverless ×5
node.js ×4
aws-lambda ×2
javascript ×2
debugging ×1
jestjs ×1
python ×1
supertest ×1
webpack ×1