With limited experience in AWS Lambda & API Gateway, it's struggling to find the correct way to return plain text. Why plain text? It's plain text in the empty function template of Python runtime.

When watching the tutorial video about using AWS Lambda on Youtube, I think it's quite easy to run the hello world example. The videos use Node.js runtime which is friendly to JSON strings. In python, the function template just return plain text, not JSON. When finishing the Lambda part and running the test, everything was just fine.

It's the API Gateway to expose Lambda function for HTTP access. Adding a API Gateway trigger will result in a resource with ANY method. If openning the URL in a browser, it just complains a 500 error "Internal Server Error". After some searches and digging in the log, I found the calling of Lambda function was OK, but the result was not parsed correctly. To parse the result plain text, you have to add Content-Type in the response header. Also body mapping template has to be updated.

Key points

* Create a new GET method.

* In Method Response, add a header "Content-Type" and empty model.

* In Integration Response, add Content-Type and 'plain/text' (including the quote signs) in Header Mapping. In Body Mapping Template, add "plain/text" and "$input.path('$')".

[1] https://kennbrodhagen.net/2016/01/31/how-to-return-html-from-aws-api-gateway-lambda/

How to return plain text from AWS Lambda & API Gateway的更多相关文章

  1. Qwiklab'实验-API Gateway, AWS Lambda'

    title: AWS之Qwiklab subtitle: 2. Qwiklab'实验-API Gateway, AWS Lambda' date: 2018-09-20 17:29:20 --- In ...

  2. 基于aws api gateway的asp.net core验证

    本文是介绍aws 作为api gateway,用asp.net core用web应用,.net core作为aws lambda function. api gateway和asp.net core的 ...

  3. Insert Plain Text and Images into RichTextBox at Runtime

    Insert Plain Text and Images into RichTextBox at Runtime' https://www.codeproject.com/Articles/4544/ ...

  4. Automated EBS Snapshots using AWS Lambda & CloudWatch

    Overview In this post, we'll cover how to automate EBS snapshots for your AWS infrastructure using L ...

  5. Plain text considered harmful: A cross-domain exploit

    referer:http://balpha.de/2013/02/plain-text-considered-harmful-a-cross-domain-exploit/ Data from aro ...

  6. [AWS] Lambda by Python

    当前统治数据分析的语言还是Python,还是暂时走:Python + GPU的常规路线好了. numba, pyculib (分装了cublas) Ref: 使用 Python 构建 Lambda 函 ...

  7. 使用AWS Lambda,API Gateway和S3 Storage快速调整图片大小

    https://www.obytes.com/blog/2019/image-resizing-on-the-fly-with-aws-lambda,-api-gateway,-and-s3-stor ...

  8. AWS Lambda 借助 Serverless Framework,迅速起飞

    前言 微服务架构有别于传统的单体式应用方案,我们可将单体应用拆分成多个核心功能.每个功能都被称为一项服务,可以单独构建和部署,这意味着各项服务在工作时不会互相影响 这种设计理念被进一步应用,就变成了无 ...

  9. AWS Lambda

    AWS Lambda 知识点总结 参考资料:Amazon 名词解释: 事件驱动型计算服务:通过事件来触发的计算服务 Amazon S3存储桶:一项面向Internet的存储服务,可以通过S3 随时在W ...

随机推荐

  1. 设置close

  2. BZOJ 3171 循环格(费用流)

    题意 一个循环格就是一个矩阵,其中所有元素为箭头,指向相邻四个格子.每个元素有一个坐标(行,列),其中左上角元素坐标为(0,0).给定一个起始位置(r,c),你可以沿着箭头防线在格子间行走.即如果(r ...

  3. 去除百度搜索结果中的广告的 js 代码

    在百度页面下控制台里执行如下代码, 然后关掉控制台 setInterval(() => { try{ Array.from( document.querySelectorAll('#conten ...

  4. [代码]--ORA-01843: 无效的月份

    1.插入的日期如果是DateTime类型的,没有影响 2.如果DateTime.ToString()获取的日期,就会报错,例如(@param_datetime = cf.GetServerDateTi ...

  5. MT【125】四点共圆

    (2017湖南省高中数学竞赛16题) \(AB\)是椭圆\(mx^2+ny^2=1(m>0,n>0,m\ne n)\)的斜率为 1 的弦.\(AB\)的垂直平分线与椭圆交于两点\(CD\) ...

  6. 【BZOJ1019】[SHOI2008]汉诺塔(数论,搜索)

    [BZOJ1019][SHOI2008]汉诺塔(数论,搜索) 题面 BZOJ 洛谷 题解 首先汉诺塔问题的递推式我们大力猜想一下一定会是形如\(f_i=kf_{i-1}+b\)的形式. 这个鬼玩意不好 ...

  7. C++ new动态数组初始化

    strlen函数是不包括‘\0’的长度的,sizeof计算的结果才包括'\0'的长度: C++ new动态数组初始化void testnew( const char* str ) { if (!str ...

  8. 基于JWT(Json Web Token)的ASP.NET Web API授权方式

    token应用流程 初次登录:用户初次登录,输入用户名密码 密码验证:服务器从数据库取出用户名和密码进行验证 生成JWT:服务器端验证通过,根据从数据库返回的信息,以及预设规则,生成JWT 返还JWT ...

  9. js调试系列: 控制台命令行API

    js调试系列目录: - 上次初步介绍了什么是控制台,以及简单的 console.log 输出信息.最后还有两个小问题,我们就当回顾,来看下怎么操作吧. 先打开百度,然后按 F12 打开后,如果不是 C ...

  10. 用phpStorm的数据库工具来管理你的数据库

    phpStorm是一个功能强大的IDE,不仅对PHP提供了支持,而且对前端HTML.CSS.JavaScript的支持也是非常不错的.此外,phpStorm还集成了很多实用的功能,下面就phpStor ...