小编Raf*_*aff的帖子

AWS Lambda@Edge Viewer 请求失败并显示“正文不是字符串、不是对象或超出最大大小”

我正在尝试创建一个 Lambda@Edge 函数来为我的 Angular SPA 应用程序返回开放图 HTML。我已将其安装到 CloudFrond“查看者请求”生命周期中。此 lambda 检查用户代理,如果它是 Facebook 或 Twitter 爬虫,它会返回 HTML(当前在 lambda 中进行硬编码以进行测试)。如果请求来自任何其他用户代理,则该请求将传递到源。传递逻辑工作正常,但如果我尝试拦截并返回爬虫程序的开放图谱 HTML,则会收到错误。

在CloudWatch中,CloudFront报告的错误是:

错误 验证错误:Lambda 函数返回无效正文,正文应为对象类型。

在 Postman 中(通过伪造用户代理),我得到 502:

Lambda 函数结果验证失败:正文不是字符串、不是对象或超出最大大小。

我正在用这个把我的头发拔出来。有任何想法吗?这是我的 lambda。

'use strict';
 
function buildReleaseResponse( request ) {
     
    const content = `<\!DOCTYPE html>
        <html lang="en">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                <meta name="viewport" content="width=device-width, initial-scale=1" />
               
                <meta property="og:type" content="website" />
                <meta property="og:title" content="Hello, World" />
                <meta property="og:description" content="This is an Open Graph test" />
                <meta property="og:image" content="https://cdn.website.com/photos/SGmzAlNmwOGpnMeijMoW9.jpg" />
                <meta property="og:url" content="https://www.website.com/hello-world" /> …
Run Code Online (Sandbox Code Playgroud)

aws-lambda angular

5
推荐指数
1
解决办法
5480
查看次数

是否可以使用Spring Boot https端点创建自定义Alexa技能

我试图在不使用Lambda的情况下创建自定义Alexa技能.因此,我已将Spring Boot应用程序部署到AWS EC2实例,设置SSL证书,并通过使用Postman调用该服务来测试该服务是否正常运行.

然后我将Alexa技能设置为"https"端点.当我在developer.amazon.com上使用Test表单时,我回过头来:

无法调用远程端点,或者它返回的响应无效.

当我直接用Postman调用服务时,我得到:

{
  "version": "1.0",
  "response": {
    "outputSpeech": {
      "type": "PlainText",
      "id": null,
      "text": "Hello, World.  I am a Spring Boot custom skill."
    },
    "card": {
      "type": "Simple",
      "title": "HelloWorld",
      "content": "Hello, World.  I am a Spring Boot custom skill."
    },
    "reprompt": null,
    "shouldEndSession": true
  },
  "sessionAttributes": null
}
Run Code Online (Sandbox Code Playgroud)

我的控制器使用Alexa技能集SDK.这是代码:

@RestController
public class AlexaController  {

    @RequestMapping(value="/alexa", 
        method=RequestMethod.POST,
        produces=MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<SpeechletResponseEnvelope> alexa(Model model) {

        String speechText = "Hello, World.  I am a Spring Boot custom skill.";

        SimpleCard …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot alexa-skills-kit

4
推荐指数
1
解决办法
5917
查看次数