我正在使用无服务器和无服务器 webpack。webpack配置非常简单:
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: {
lambda: './lambda.js',
},
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
externals: [nodeExternals()],
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
include: __dirname,
exclude: /node_modules/,
}, {
test: /\.json$/,
loader: 'json-loader',
}],
},
stats: "verbose",
};
Run Code Online (Sandbox Code Playgroud)
无服务器.yml:
plugins:
- serverless-webpack
- serverless-secrets-plugin
- serverless-plugin-split-stacks
- serverless-offline
custom:
webpack:
webpackConfig: ./webpack.config.js
stage: ${opt:stage, self:provider.stage}
provider:
name: aws
runtime: nodejs8.10
functions: …Run Code Online (Sandbox Code Playgroud) 当我使用以下方法部署我的无服务器 API 时:
serverless deploy
Run Code Online (Sandbox Code Playgroud)
lambda 层已创建,但是当我运行该函数时,出现此错误:
"Cannot find module 'request'"
Run Code Online (Sandbox Code Playgroud)
但是,如果我通过控制台手动上传 .zip 文件(部署时上传的完全相同的文件),它工作正常。
任何人都知道为什么会发生这种情况?
environment:
SLS_DEBUG: "*"
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:api-type, 'uat'}-${opt:api, 'payment'}
region: ca-central-1
timeout: 30
memorySize: 128
role: ${file(config/prod.env.json):ROLE}
vpc:
securityGroupIds:
- ${file(config/prod.env.json):SECURITY_GROUP}
subnetIds:
- ${file(config/prod.env.json):SUBNET}
apiGateway:
apiKeySourceType: HEADER
apiKeys:
- ${file(config/${opt:api-type, 'uat'}.env.json):${opt:api, "payment"}-APIKEY}
functions:
- '${file(src/handlers/${opt:api, "payment"}.serverless.yml)}'
package:
# individually: true
exclude:
- node_modules/**
- nodejs/**
plugins:
- serverless-offline
- serverless-plugin-warmup
- serverless-content-encoding
custom:
contentEncoding:
minimumCompressionSize: 0 # Minimum body size required for …Run Code Online (Sandbox Code Playgroud) 我有一个 Google Cloud Function,其中包含要在不同路径上调用的多个模块。
我正在使用无服务器框架来部署我的函数,但它有每个函数只能有一个路径的限制。
我想在一个函数中使用多个路径,就像在 AWS 无服务器框架中一样。
假设user云函数有两条/user/add路径/user/remove;两个路径都应该调用相同的函数。
像这样的东西:
serverless.yml
functions:
user:
handler: handle
events:
- http: user/add
- http: user/remove
Run Code Online (Sandbox Code Playgroud)
如何为一个 GCF 提供多个 API 端点?
我的serverless.yml文件中的这些行有问题。我正在使用无服务器插件serverless-single-page-app-plugin。
# CustomOriginConfig:
# HTTPPort: 80
# HTTPSPort: 443
# OriginProtocolPolicy: https-only
## In case you want to restrict the bucket access use S3OriginConfig and remove CustomOriginConfig
S3OriginConfig:
OriginAccessIdentity: origin-access-identity/cloudfront/E127EXAMPLE51Z
Run Code Online (Sandbox Code Playgroud)
我想使用s3OriginConfig和禁用通过 S3 存储桶的访问。我可以手动执行此操作。但我想得到如下图所示的效果:

我已在 AWS SSM 参数存储 UI 中将键值对配置为my-ssm-key= ssm-value。
我有以下基于无服务器构建的 CF YAML 模板:
service: redirect-test
provider:
name: aws
runtime: python3.8
environment:
ssm_value: '{{resolve:ssm:my-ssm-key:1}}'
ssm_value_is_correct: !If [SSM_KEY_IS_CORRECT, yes, no]
functions:
hello:
handler: handler.hello
resources:
Conditions:
SSM_KEY_IS_CORRECT:
!Equals
- '{{resolve:ssm:my-ssm-key:1}}'
- 'ssm-value'
Run Code Online (Sandbox Code Playgroud)
在部署堆栈时,环境变量被设置为ssm_value=ssm-value和ssm_value_is_correct= no。
为什么条件语句解析为“否”而不是“是”?在条件中使用 SSM 参数存储值的正确方法是什么?
amazon-web-services aws-cloudformation ssm serverless-framework
我正在创建一个应该写入 dynamodb 的函数,我想使用 aws-xray-sdk 生成跟踪。
我的功能是
private readonly docClient: DocumentClient = AWS.DynamoDB.DocumentClient()
async createTodo(todoItem: TodoItem): Promise<TodoItem> {
await this.docClient.put({
TableName: this.todosTable,
Item: todoItem
}).promise()
return todoItem
}
Run Code Online (Sandbox Code Playgroud)
当我如上所述仅使用来自 aws sdk 的文档客户端时,这非常有效,但是因为当我通过 aws-xray-sdk 传递 aws-sdk 并想要使用 sdk 时需要跟踪,它会引发错误。这就是我构建它的方式。
import * as AWS from 'aws-sdk'
import * as AWSXRay from 'aws-xray-sdk'
const XAWS = AWSXRay.captureAWS(AWS)
Run Code Online (Sandbox Code Playgroud)
然后当我做
private readonly docClient: DocumentClient = XAWS.DynamoDB.DocumentClient()
我收到错误
TS2339: Property 'DocumentClient' does not exist on type
'PatchedAWSClientConstructor<ClientConfiguration, typeof DynamoDB>'.
Run Code Online (Sandbox Code Playgroud)
我该如何消除此错误或可能获得可用于使用 aws-xray 进行跟踪的文档客户端。
依赖性。"aws-xray-sdk": "^2.2.0", "aws-sdk": "^2.433.0",
node.js amazon-dynamodb typescript serverless-framework aws-xray
我正在尝试找出一种使用无服务器框架和无服务器离线在 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 文件没有源映射。我尝试将outfilelaunch.json的字段设置为python 文件本身,但这显然不起作用。
在此先感谢那些能够提供帮助的人。 …
python debugging amazon-web-services serverless-framework serverless-offline
运行任一命令时:
sudo serverless package or sudo serverless deploy
错误:错误:异常:回溯(最近一次调用):文件“/var/lang/lib/python3.6/shutil.py”,第 550 行,移动 os.rename(src, real_dst) OSError:[Errno 18 ] 无效的跨设备链接:'/tmp/pip-target-wqc5grcw/lib/python/setuptools' -> '/var/task/setuptools'
在处理上述异常的过程中,又发生了一个异常:
回溯(最近一次调用):文件“/var/lang/lib/python3.6/site-packages/pip/_internal/cli/base_command.py”,第 228 行,在 _main status = self.run(options, args ) 文件“/var/lang/lib/python3.6/site-packages/pip/_internal/cli/req_command.py”,第 182 行,在包装器 return func(self, options, args) 文件“/var/lang/ lib/python3.6/site-packages/pip/_internal/commands/install.py”,第 456 行,在运行 options.target_dir、target_temp_dir、options.upgrade 文件“/var/lang/lib/python3.6/site- package/pip/_internal/commands/install.py”,第 514 行,在 _handle_target_dir target_item_dir 文件“/var/lang/lib/python3.6/shutil.py”,第 561 行,在 move symlinks=True 中)文件“/var /lang/lib/python3.6/shutil.py”,第 321 行,在 copytree os.makedirs(dst) 文件“/var/lang/lib/python3.6/os.py”,第 220 行,在 makedirs mkdir(名称,模式)PermissionError:[Errno 13] 权限被拒绝:'/var/task/setuptools'
我创建了几个不同的项目,它们在本地工作,但在尝试部署或打包时,它们从未超出这个无效的交叉链接设备错误。
我有哪些选择?
无服务器部署抛出spawn serverless ENOENT\n尝试部署时出现以下错误client-service,尽管在此之前所有服务都已部署。
\n\n错误:生成无服务器 ENOENT
\n
使用以下版本进行无服务器和无服务器组合
\n"@serverless/compose": "^1.3.0",\n"serverless": "^3.22.0",\nRun Code Online (Sandbox Code Playgroud)\nserverless-compose.ts 配置
\nconst serverlessCompose = {\n services: {\n "infra-test": {\n path: "infra-test",\n },\n "client-service": {\n path: "client-\'service\'",\n dependsOn: ["infra-test"],\n },\n },\n};\n\nmodule.exports = serverlessCompose;\n\nRun Code Online (Sandbox Code Playgroud)\n带有使用标志的完整命令名称(如果不适用,请填写“N/A”)
\nserverless deploy --stage sbx
完整的命令输出。
\ninfra-test \xe2\x80\xba \ninfra-test \xe2\x80\xba Stack Outputs:\ninfra-test \xe2\x80\xba ServerlessDeploymentBucketName: infra-test-sbx-serverlessdeploymentbucket-yg91fd\ninfra-test \xe2\x80\xba 3 deprecations found: run \'serverless doctor\' for more details\ninfra-test \xe2\x80\xba deployed\nclient-service \xe2\x80\xba deploying\nclient-service \xe2\x80\xba Running "serverless deploy …Run Code Online (Sandbox Code Playgroud) node.js typescript serverless-framework serverless-architecture serverless
serverless ×4
aws-lambda ×3
node.js ×3
python ×2
typescript ×2
amazon-s3 ×1
aws-xray ×1
debugging ×1
javascript ×1
ssm ×1
webpack ×1