我有一个在无服务器框架上开发的 AWS Lambda 函数的工作开发环境,使用 DynamoDB(插件: serverless-offline, serverless-dynamodb-local 。删除 node_modules 并重新安装后,我失去了启动开发服务器的能力,这我曾经做过 serverless offline start
serverless offline 工作正常,但如果我尝试在本地运行 dynamodb,则会引发以下错误:
Reference Error ----------------------------------------
options is not defined
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
ReferenceError: options is not defined
at BbPromise.resolve.then (/Users/pablo/Documents/myProject/node_modules/serverless-dynamodb-local/index.js:164:21)
From previous event:
at PluginManager.invoke (/Users/pablo/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/lib/classes/PluginManager.js:236:22)
at PluginManager.run (/Users/pablo/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/lib/classes/PluginManager.js:255:17)
at variables.populateService.then (/Users/pablo/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/lib/Serverless.js:99:33)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event: …Run Code Online (Sandbox Code Playgroud) 我按照本教程https://serverless-stack.com/使用 AWS 服务(S3、Lambda、Cognito、DynamoDB)和带有 ReactJS 的无服务器框架创建了一个无服务器应用程序。本教程使用 AWS Cognito 用户池和身份池进行用户管理和身份验证。本教程中的应用程序是一个“记笔记”应用程序,它在应用程序中没有基于角色的访问控制。
然而,我正在创建的应用程序需要 RBAC,在阅读了它之后,我明白可以使用“用户组”或“联合身份”来实现 RBAC。但是,我仍然无法弄清楚如何在我的应用程序中正确使用它们中的任何一个。
这是我到目前为止在应用程序中所做的
政策
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*",
"cognito-identity:*"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::YOUR_S3_UPLOADS_BUCKET_NAME/${cognito-identity.amazonaws.com:sub}*"
]
},
{
"Effect": "Allow",
"Action": [
"execute-api:Invoke"
],
"Resource": [
"arn:aws:execute-api:YOUR_API_GATEWAY_REGION:*:YOUR_API_GATEWAY_ID/*"
]
}
]
} …Run Code Online (Sandbox Code Playgroud) 我正在使用无服务器框架(aws Lambda 函数),但我希望身份验证由 firebase 完成。是否可以将这两者结合起来?
我有一个 lambda 函数,它利用 Graphql 和 webscraping 返回一些数据作为响应。有时它不会出现像 502 这样的错误,有时它不会。对我来说,502 错误似乎是完全随机的,因为我一直使用相同的数据发送相同的请求。
我的超时在 AWS 控制台中设置为 5 分钟。
这些是我得到的错误(在浏览器中):
无法加载 [BIG URL] 请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问源 '[mydomainurl]'。响应具有 HTTP 状态代码 502。
spread.js:25 GET [大网址] 502 ()
但是,当我转到 Chrome 中的“网络”选项卡并在浏览器中查看复制的链接地址时,我会收到带有我想要的数据的 JSON 响应。我在 CloudWatch 中找不到错误。
标题
响应头
content-length: 36
content-type: application/json
date: Fri, 13 Apr 2018 06:17:06 GMT
status: 502
via: 1.1 67284fcf464f6f1529cc1e521669622c.cloudfront.net (CloudFront)
x-amz-apigw-id: FRC2oEiuDoEF_YQ=
x-amz-cf-id: O1VfzIVPySw657r6WV34EvcPMTyeT7eFUBnM3P30NXBmdjTeWHfryw==
x-amzn-requestid: 4766f279-3ee2-11e8-9e72-bdddab0f02d6
x-cache: Error from cloudfront
Run Code Online (Sandbox Code Playgroud)
请求头
:authority: wqbgu8c3ql.execute-api.eu-west-1.amazonaws.com
:method: GET
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda aws-api-gateway graphql-js serverless-framework
如何获取无服务器框架在我的 serverless.yml 文件中创建的 API 网关资源的 ARN?
我想获取 API 网关资源的 ARN,以便我可以在 IAM 策略中使用它在网关上执行基于 IAM 的授权。
I am trying to create a custom Lambda authorizer that will be shared between a few different services/serverless stacks. If I understand the documentation here https://serverless.com/framework/docs/providers/aws/events/apigateway/#note-while-using-authorizers-with-shared-api-gateway, that means that I need to create a shared authorizer resource in a “common resources” service/serverless stack, and then refer to that shared authorizer from my other services. First of all: Is my understanding correct?
If my understanding is correct, my next question becomes: How do I do this? The documentation doesn’t provide …
我正在创建一个应该写入 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'
我创建了几个不同的项目,它们在本地工作,但在尝试部署或打包时,它们从未超出这个无效的交叉链接设备错误。
我有哪些选择?
我正在使用新的无服务器 TypeScript monorepo 启动一个新项目!使用了aws-nodejs-typescript模板,它提供了一个serverless.ts配置文件。几周后,我现在在命令行上从 Serverless 收到以下很好的警告:
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from “{stage}-{service}” to “{service}-{stage}”.
Set “provider.apiGateway.shouldStartNameWithService” to “true” to adapt to the new behavior now.
More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Run Code Online (Sandbox Code Playgroud)
好的!看起来很棒,我喜欢新的命名。由于这是一个新项目,最好在我们发布任何内容之前立即应用新命名。但是,看起来 TypeScript 定义相当严格,似乎还不允许使用新变量:
Loading failed with: TSError: ? Unable to compile TypeScript:
serverless.ts(44,7): error TS2322: Type ‘{ minimumCompressionSize: number; shouldStartNameWithService: true; }’ is not assignable to type ‘ApiGateway’.
Object literal may only specify known properties, and ‘shouldStartNameWithService’ does …Run Code Online (Sandbox Code Playgroud) aws-lambda ×3
node.js ×2
python ×2
aws-cognito ×1
aws-xray ×1
debugging ×1
graphql-js ×1
serverless ×1
typescript ×1