我正在学习本教程:http://www.thymeleaf.org/doc/layouts.html(获得Thymeleaf布局方言部分).在那里你可以找到一个例子:
<!DOCTYPE html>
<html>
<head>
<!--/* Each token will be replaced by their respective titles in the resulting page. */-->
<title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Task List</title>
...
</head>
<body>
<!--/* Standard layout can be mixed with Layout Dialect */-->
<div th:replace="fragments/header :: header">
...
</div>
<div class="container">
<div layout:fragment="content">
...
</div>
<div th:replace="fragments/footer :: footer">© 2014 The Static Templates</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
th:replace在上面的示例中,页脚和标题被标记替换,而在布局文件中<head>有<title>标记.
基本上,我想用整个<head>标签替换th:replace.因此,我有:
我的布局文件:
<!DOCTYPE html>
<html> …Run Code Online (Sandbox Code Playgroud) 我想serverless.yml在不同的环境中重用我的(dev,test,prod).
在配置中我有:
provider:
name: aws
stage: ${opt:stage, 'dev'}
environment:
NODE_ENV: ${self:provider.stage}
Run Code Online (Sandbox Code Playgroud)
现在价值将是dev,test或prod(全部为小写).
有没有办法将它转换为UpCase()的方式,输入和self:provider:stage将保持原样(即小写),但NODE_ENV的值将是大写?
我正在尝试使用serverless-domain-manager插件在无服务器中设置不同的自定义域.
我遵循了本教程:https: //serverless.com/blog/serverless-api-gateway-domain/
但该示例未显示如何设置多个自定义域.
在我的serverless.yml档案中,我有:
plugins:
- serverless-domain-manager
custom:
customDomain:
basePath: ''
domainName: MY_DOMAIN_HERE
stage: dev
createRoute53Record: true
Run Code Online (Sandbox Code Playgroud)
如何添加其他域名?例如,对于prod舞台?
在执行时sls deploy -s MY_STAGE -v,无服务器在打包期间停止:
...
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Packaging service...
Run Code Online (Sandbox Code Playgroud)
我使用verbose,并设置SLS_DEBUG=*为获取更多信息。但是,这并没有显示包装发生了什么以及它为什么等待/挂起......
我还能做些什么来检查导致包装挂起的原因?
更多细节:
实际导致问题的包是puppeteer. 如果我在代码中注释掉:
// const puppeteer = require('puppeteer');
Run Code Online (Sandbox Code Playgroud)
这有帮助并且sls deploy有效。但是,我想使用puppeteer.
此外,我还设置了PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1- 这没有任何区别。
在.serverless文件夹中,除了使用puppeteer.
如果我这样做,sls package -s MY_STAGE它会挂在同一个地方。
我的环境:
Your Environment Information -----------------------------
OS: win32
Node Version: 8.9.4
Serverless Version: 1.26.1
Run Code Online (Sandbox Code Playgroud) 如何BatchWriteItem在 DynamoDB 中创建受控失败?
基本上,我想在DynamoDB模拟故障(故意破BatchWriteItem),这样我就可以确保取逻辑的方式UnprocessedItems在response工作正常。
来自文档:http : //docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
通常,您会在循环中调用 BatchWriteItem。每次迭代都会检查未处理的项目,并提交一个包含这些未处理项目的新 BatchWriteItem 请求,直到所有项目都已处理完毕。
下面是讨论的两个类似的解决方案,它们使用 do-while 循环和回调:
带有 do-while 的 JAVA:
带回调的节点:
如何使用 AWS JavaScript SDK (dynamoDB) 处理 UnprocessedItems?
如何准备“损坏的” BatchWriteItem 请求以进行测试?
DynamoDB 会陷入无限循环吗?即BatchWriteItem返回UnprocessedItems,代码需要UnprocessedItems和调用BatchWriteItem并UnprocessedItems一次又一次地返回?
跑步时sls offline start我得到:
$ sls offline start
events.js:160
throw er; // Unhandled 'error' event
^
Error: spawn java ENOENT
at exports._errnoException (util.js:1020:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:367:16)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
Run Code Online (Sandbox Code Playgroud)
我serverless.yml有:
plugins:
- serverless-dynamodb-local
- serverless-offline
- serverless-mocha-plugin
Run Code Online (Sandbox Code Playgroud) I've compared three fibonacci algorithms with jsben.ch and as expected first one is the fastest (it even got a little award icon):
Yet, I can't find what the numbers next to code block result mean? The higher, the better but what's the unit?
这是我的 lambda:
exports.handler = async (event) => {
const hex = '89504e470d0a1a0a0000000d49484452000000a0000000a00800000000aea438f10000053e4944415478daed99bd6b2a4d1487effff4834504610988208204040b411002161616818010b0b0106e110b411041d258a4b0085858489a142902172e046c2c445208161224582c72dec29dd98fd911a2ee7a7939db654edc3c998fe79c39fea27ffcf9c5800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc8800cc880ff4bc09bab4cae58aed61a0f9dc741bfdb6adc554ab974d24c2d699b3693d962b5d668f506bd76b37e5b29e5b3c9d42759d99899ce97ef1aed6eb7ddac550a693356209a18f1ab6cb15a7fe8f43aad7ab5983163b9d30153d03c7f68630406de6811309a27eaa9a3d7a7037e34f3011c66b9f54df4524b2b7ff1b6bda1dde37dc1331a2fb5a6449fedbb8c7bd4283ccccfb20737936b2f457a6889d8bce20edccde48766b772343392bfbe1bcb7fc9e86cce7748ac41dc859159bb6343179f7b7c27d0db967b781ab3977c7ede53fcee22fceb0db565e0c5fb91fd60d7f7a6fa7e1156e7d6ccb3c448ec7cd39b1391b1776700006efd2f1ad827e9ec1e947b4a51c39b88fcf60c2f0120f9e5ffed2100d44310f522268ea4e50f89dd76b5758fbeaaab2e76447c194626f92d266aa2a8484446eed11a806a80f995a93e17e0a7f06185745398778dad0cc0508feada008ccf7072714d4c94f267df45e4d5196b05cfd400402da462e1afc0682aa1a21d293a131807126bf525d7aaa7ce57cd88fc955072c044b0bfbb776c477dc51b804268e59674e1c01fd9896458168e8901e6265856a3d000b7a68d91dd05da0d003ef63f3700f4d5372c0d20698557b0b6020e83cd9eb423fbccb13080d4960225d809b1a23e609abe609f1111dd03780a283a9280b10a1190aa5ad37c25ecc83d11cd0c2013b092633b1e1ee09bde340fa2cefbd41f8592b349c3ba345d6b4db33424fb14406ea77e78ea3165388003ad69ec420f88ad2a4109db3edaa390013709ad696682bdac91f126fe43c71c752f6e6a4de39c204d413a08a8afcf0f28e74935cd1f87ef46b37f7fe698e33a0b65ad6964c900fcd118e09ec2079ce84d234365dd9de12302402bad358d2c19d256701a2e5204804e52534d330cacfdf74f47b9f68505b88e694d234b0655d3561248599100d2bdde347dedc56a0ca017517ff0436f1a192a045ce662ab88001d9d28a6b9d3997af693dbfac980239d69668eaacb6a1a9e4606b8bdd298e6169a16d3260194283240a7a1355076a05cfeaa3f0d8f230494b59fd73415c058543cb5bffde48e72ccf180ce5abefa2ef64da7cb50f3761e7a1425e07b9069ca407ce59c7163e13edcb175a48094534df30ea0ed2e191aee3e529da2057c524d7303985f44b4cbcadadf9586a711037e27fca67903f0e82d191eec349cd254b061023aedcc81935eec5e822c19eceed65873870a17700eaf695e000cfd254357ac7dda8a1c5076556dd3e4816bcbdf6530bfedfcd7a7e8015f3ca6997896b1e55eff26105f5f00709771996697f3545832d3a42cda248e76cc6980f4e8fa7a64e42bb0449701437a3ade312702aee3d23456d6575fc9ba2b6be58e77cc8980ce340d9e951ba5ec32344e70cca98053394d19df379d9e2ec3f18e3915904aae2fa7e7fa589f2e053876201a5a0b9de0989301ada48458eaeb9d065d0c903a02a2a5c69e832aeba80157b690cd8055b452071a4951018a7b70ff80c85f2e0ab8b749721b14db980090de5d1490f208feca465e4e1fe9b2804300598d88573120fe7561c0ad79e046de38d131e700a4ee81526061c6e71707a4e58153f0bda1cb0386fb30200332200332200332200332200332200332200332200332200332200332200332200332e03ffafc0761478d7dbc33444a0000000049454e44ae426082'
const image = Buffer.from(hex, 'hex');
const result = /* "data:image/png;base64," + */ image.toString('base64');
const response = {
statusCode: 200,
headers: {
'Content-Type': 'image/png'
},
body: result,
isBase64Encoded: true
}
return response;
};
Run Code Online (Sandbox Code Playgroud)
它以JSON 的形式返回。
接下来,在 API Gateway 中,GET - 集成响应:
我通过 AWS 控制台设置了以下内容:
Content handling: Convert to binary (if needed)
标题映射:
Content-Type: 'image/png'
映射模板:
image/png. 目前我使用:
{
"base64Image": $input.path('$.body')
}
Run Code Online (Sandbox Code Playgroud)
最后,在 GET - 方法响应中:
200 …
我有一个用Node.JS编写的无服务器lambda函数.
返回错误代码的最佳/正确方法是什么?
我现在使用的模式(它的工作原理!)是:
module.exports.endpoint = (event, context, callback) => {
const response = {
statusCode: 404,
body: JSON.stringify({ message: 'Hello World!' })
};
callback(null, response);
}
Run Code Online (Sandbox Code Playgroud)
当我拨打电话时,例如从POSTMAN到我的终端,我得到:
Status: 404 Not Found 这正是我所期待的.
而且,在日志中我可以看到:
Serverless: GET / (?: get)
Serverless: [404] {"statusCode":404,"body":"{\"message\":\"Hello World!\"}"}
Run Code Online (Sandbox Code Playgroud)
这很好用.
令我困扰的是,我正在传递null错误.看看其他一些教程/示例我发现了以下模式:
https://aws.amazon.com/blogs/compute/error-handling-patterns-in-amazon-api-gateway-and-aws-lambda/
https://serverless.com/framework/docs/providers/aws/events/apigateway/
callback ("the sky is falling!");
callback("[BadRequest] Validation error: Missing field 'name'");
callback("[404] Not Found");
callback(new Error('[404] Not found'));
callback(JSON.stringify(myErrorObj));
所有这些都很有意义,你可以指定HTTP状态代码 - 但我最终获得的是HTTP状态代码200.当我查看日志时,我可以看到错误是在200之后:
Serverless: GET / (?: get)
Serverless: …Run Code Online (Sandbox Code Playgroud) node.js aws-lambda aws-api-gateway serverless-framework serverless
使用 REST API(AWS API Gateway v1),我们可以X-API-Key在请求中使用标头并维护 API 密钥来控制对给定端点的访问。
在 AWS 中,如果我转到 API Gateway 并选择 REST API (v1),则在资源下我会看到:API Key Required在 API 密钥下我可以找到我的密钥。
使用serverless它可以像这样配置:
provider:
apiKeys:
- my-api-key
functions:
hello:
handler: handler.hello
events:
- http:
path: /hello
method: get
private: true
Run Code Online (Sandbox Code Playgroud)
但如果我切换到httpApi然后我得到:
Configuration warning at 'functions.hello.events[0].httpApi': unrecognized property 'private'
Run Code Online (Sandbox Code Playgroud)
此外,在 API Gateway 中,在 HTTP API (v2) 下,任何地方都没有 API 密钥。
当我检查文档时,REST API 下有很大一部分关于 API 密钥:https: //www.serverless.com/framework/docs/providers/aws/events/apigateway 但 API Gateway HTTP API 没有任何关于 API 密钥的内容: https: …
rest amazon-web-services aws-api-gateway serverless aws-http-api
我有以下格式的传入 SOAP 消息:
const soap = `
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header/>
<env:Body property="def">
<Root>
<Abc attr="abc">123456</Abc>
</Root>
</env:Body>
</env:Envelope>
`;
Run Code Online (Sandbox Code Playgroud)
我期望得到的是<env:Body>不变的内容:
<Root>
<Abc attr="abc">123456</Abc>
</Root>
Run Code Online (Sandbox Code Playgroud)
要提取正文,我使用简单的正则表达式:
function getSoapBody(xmlStr) {
let soapBody = null;
if (xmlStr) {
const soapBodyRegex = /<env:Body>([\s\S]*)<\/env:Body>/im;
const soapBodyRegexMatchResult = xmlStr.match(soapBodyRegex);
soapBody = soapBodyRegexMatchResult[1];
}
return soapBody;
}
Run Code Online (Sandbox Code Playgroud)
但是,使用正则表达式获取 body 当然并不理想。
此外,我不想重新发明轮子,我正在寻找一种解决方案(甚至 npm 包),无论使用什么前缀(如果前缀发生变化,上面的正则表达式都会失败)或者是否有可选属性,它基本上都会 getSoapBody等等。
serverless ×5
aws-lambda ×3
node.js ×3
javascript ×2
algorithm ×1
aws-http-api ×1
benchmarking ×1
dialect ×1
fibonacci ×1
layout ×1
puppeteer ×1
rest ×1
soap ×1
thymeleaf ×1
yaml ×1