以下代码随机失败:
执行上下文被破坏,很可能是因为导航。
这是为什么?任何解决方法?
我使用 puppeteer 版本 1.19.0
注意:我正在寻找一种通用解决方案,它允许导航到具有重定向的页面和没有重定向的页面。
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.setCacheEnabled(false);
const response = await page.goto("https://docs.cypress.io/", {
waitUntil: "networkidle0",
timeout: 60000
});
const pageUrls = await page.evaluate(() => {
const links = Array.from(document.querySelectorAll("a"));
return links.map(link => link.href);
});
console.log({ pageUrls });
} catch (error) {
console.log(error.message);
}
await browser.close();
})();
Run Code Online (Sandbox Code Playgroud) 尝试运行无服务器时收到以下警告。
无服务器警告 -------------------------------------
找不到满足声明 'opt:stage' 的有效选项。下面是我的 serverless.yml 文件
# Serverless Config
service: api-service
# Provider
provider:
name: aws
runtime: nodejs8.10
region: ${opt:region, 'ap-east-1'}
stage: ${opt:stage, 'dev'}
# Enviroment Varibles
environment:
STAGE: ${self:custom.myStage}
MONGO_DB_URI: ${file(./serverless.env.yml):${opt:stage}.MONGO_DB_URI}
LAMBDA_ONLINE: ${file(./serverless.env.yml):${opt:stage}.LAMBDA_ONLINE}
# Constants Varibles
custom:
# environments Variables used for convert string in upper case format
environments:
myStage: ${opt:stage, self:provider.stage}
stages:
- dev
- qa
- staging
- production
region:
dev: 'ap-east-1'
stage: 'ap-east-1'
production: 'ap-east-1'
# Function
functions:
testFunc:
handler: index.handler
description: ${opt:stage} API's …Run Code Online (Sandbox Code Playgroud) 我正在构建一个无服务器应用程序,它在资源中定义了一个 SQS 队列,如下所示:
resources:
Resources:
TheQueue:
Type: "AWS:SQS:Queue"
Properties:
QueueName: "TheQueue"
Run Code Online (Sandbox Code Playgroud)
我想从其中一个函数中向这个队列发送消息。如何从函数内部访问 URL?我想把它放在这里:
const params = {
MessageBody: 'message body here',
QueueUrl: 'WHATS_THE_URL_HERE',
DelaySeconds: 5
};
Run Code Online (Sandbox Code Playgroud) 我正在运行我的 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) 今天早上,我项目的无服务器部署开始失败。我没有更改代码中的任何内容,最后一次成功部署大约是在一周前。
这是部署日志:
Error --------------------------------------------------
Error: Unknown object type "asyncfunction"
at Object._object (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:218:17)
at Object._function (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:319:14)
at Object.dispatch (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:185:30)
at /usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:246:18
at Array.forEach (<anonymous>)
at Object._object (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:242:21)
at Object._function (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:319:14)
at Object.dispatch (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:185:30)
at /usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:246:18
at Array.forEach (<anonymous>)
at Object._object (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:242:21)
at Object.dispatch (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:185:30)
at /usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:246:18
at Array.forEach (<anonymous>)
at Object._object (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:242:21)
at Object.dispatch (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:185:30)
at /usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:246:18
at Array.forEach (<anonymous>)
at Object._object (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:242:21)
at Object.dispatch (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:185:30)
at /usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:246:18
at Array.forEach (<anonymous>)
at Object._object (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:242:21)
at Object.dispatch (/usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:185:30)
at /usr/local/lib/node_modules/serverless/node_modules/object-hash/index.js:246:18
at Array.forEach …Run Code Online (Sandbox Code Playgroud) 谁能帮我找出问题所在吗?
我正在我的无服务器 yml 中导入此 cloudformation 资源。这是我的功能配置:
Resources:
eventHandler:
Type: AWS::Serverless::Function
Properties:
CodeUri: eventLambda/
Handler: dist/app.eventHandler
Runtime: nodejs12.x
FunctionName: eventHandler
Run Code Online (Sandbox Code Playgroud)
这是我引用它的地方:
eventSourceRule:
Type: 'AWS::Events::Rule'
Properties:
Name: eventSourceRule
EventBusName: omnibus-${self:custom.stage}
EventPattern: |
{
"source": ["op.api"]
}
RetryPolicy:
MaximumRetryAttempts: 5
MaximumEventAgeInSeconds: 900
DeadLetterConfig:
Type: SQS
QueueLogicalId: EBRuleDLQ
Targets:
- Arn:
Fn::GetAtt:
- 'EventHandlerLambdaFunction'
- 'Arn'
Id: 'eventSourceRule'
Run Code Online (Sandbox Code Playgroud)
请注意,我已经尝试过了eventHandler,EventHandler但这些都不起作用。这就是我收到的错误:
The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource EventHandlerLambdaFunction
Run Code Online (Sandbox Code Playgroud) 我创建了一个无服务器 Redshift 实例,并尝试从 S3 存储桶导入 CSV 文件。
我创建了一个具有完整 Redshift + Redshift 无服务器访问权限和 S3 读取访问权限的 IAM 角色,并将该角色添加为Serverless Configuration的Permissions设置下的默认角色。基本上,我已经尝试根据文档做任何我认为必要的事情。
但是,这些文档目前仅针对正常的 EC2 托管 Redshift,而不是针对无服务器版本,因此可能有一些我忽略的内容。
但是当我尝试运行 COPY 命令(由 UI 生成)时,出现以下错误:
ERROR: Not authorized to get credentials of role arn:aws:iam::0000000000:role/RedshiftFull Detail: ----------------------------------------------- error: Not authorized to get credentials of role arn:aws:iam::00000000:role/RedshiftFull code: 30000 context: query: 18139 location: xen_aws_credentials_mgr.cpp:402 process: padbmaster [pid=8791] ----------------------------------------------- [ErrorId: 1-61dc479b-570a4e96449b228552f2c911]
Run Code Online (Sandbox Code Playgroud)
这是我尝试运行的命令:
ERROR: Not authorized to get credentials of role arn:aws:iam::0000000000:role/RedshiftFull Detail: ----------------------------------------------- error: Not authorized …Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-iam amazon-redshift serverless amazon-redshift-serverless
当我使用 Serverless Framework 2 时,我定义了授权者,如下所示。
sample:
handler: sample.handler
events:
- http:
path: sample
method: get
cors: true
authorizer: verify-token
Run Code Online (Sandbox Code Playgroud)
但无服务器框架 3 不支持它。现在,我收到以下错误。
Incorrect type. Expected "Aws.HttpAuthorizer".yaml-schema: Serverless Framework Configuration
Run Code Online (Sandbox Code Playgroud)
我查看了他们已弃用的文档但我找不到解决方案。如何解决这个问题?
使用 sls deploy 进行无服务器部署并收到错误“spawn python3.8 ENOENT”
\nubuntu@jumpboxAndawscli:$ sudo sls deploy --stage prod\nServerless: Configuration warning at \xe2\x80\x98provider\xe2\x80\x99: unrecognized property \xe2\x80\x98configfile\xe2\x80\x99\nServerless:\nServerless: Learn more about configuration validation here:\nServerless:\nServerless: Updated deployment bucket public access block\nServerless: [serverless-package-external] is complete\nServerless: Generated requirements from /data/integrations/requirements.txt in /data/integrations/.serverless/requirements.txt\xe2\x80\xa6\nServerless: Installing requirements from /home/ubuntu/.cache/serverless-python-requirements/c83840509c18324c044b580033bb40d7104080235af12a1d9e3d118cf0675070_x86_64_slspyc/requirements.txt \xe2\x80\xa6\nServerless: Using download cache directory /home/ubuntu/.cache/serverless-python-requirements/downloadCacheslspyc\n\nError ---------------------------------------------------\n\nError: spawn python3.8 ENOENT\nat Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)\nat onErrorNT (internal/child_process.js:470:16)\nat processTicksAndRejections (internal/process/task_queues.js:84:21)\n\n For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.\nYour Environment Information ---------------------------\nOperating System: linux\nNode Version: 12.22.1\nFramework Version: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 M1 Mac 上使用 SAM CLI。
\n我按照这些文档中概述的步骤进行操作:
\nsam init\ncd sam-app\nsam build\nsam deploy --guided\nRun Code Online (Sandbox Code Playgroud)\n我没有修改代码或 yaml 文件。\n我可以按预期启动本地 Lambda 函数:
\n\xe2\x9e\x9c sam-app sam local start-api\nMounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]\nYou can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you used sam build before running local commands, you will need to re-run sam build for the changes …Run Code Online (Sandbox Code Playgroud) serverless ×10
node.js ×3
aws-lambda ×2
python ×2
amazon-iam ×1
amazon-sqs ×1
aws-sam-cli ×1
docker ×1
javascript ×1
jenkins ×1
puppeteer ×1
resources ×1