How to return plain text from AWS Lambda & API Gateway
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的更多相关文章
- Qwiklab'实验-API Gateway, AWS Lambda'
title: AWS之Qwiklab subtitle: 2. Qwiklab'实验-API Gateway, AWS Lambda' date: 2018-09-20 17:29:20 --- In ...
- 基于aws api gateway的asp.net core验证
本文是介绍aws 作为api gateway,用asp.net core用web应用,.net core作为aws lambda function. api gateway和asp.net core的 ...
- Insert Plain Text and Images into RichTextBox at Runtime
Insert Plain Text and Images into RichTextBox at Runtime' https://www.codeproject.com/Articles/4544/ ...
- 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 ...
- 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 ...
- [AWS] Lambda by Python
当前统治数据分析的语言还是Python,还是暂时走:Python + GPU的常规路线好了. numba, pyculib (分装了cublas) Ref: 使用 Python 构建 Lambda 函 ...
- 使用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 ...
- AWS Lambda 借助 Serverless Framework,迅速起飞
前言 微服务架构有别于传统的单体式应用方案,我们可将单体应用拆分成多个核心功能.每个功能都被称为一项服务,可以单独构建和部署,这意味着各项服务在工作时不会互相影响 这种设计理念被进一步应用,就变成了无 ...
- AWS Lambda
AWS Lambda 知识点总结 参考资料:Amazon 名词解释: 事件驱动型计算服务:通过事件来触发的计算服务 Amazon S3存储桶:一项面向Internet的存储服务,可以通过S3 随时在W ...
随机推荐
- js手写俄罗斯方块
代码如下 html: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...
- 免费SSL证书(https网站)申请
如何拥有一个自己的免费的SSL证书,并且能够长期拥有.这篇文章让你找到可用的免费证书o(* ̄︶ ̄*)o 各厂商提供的免费SSL基本是Symantec(赛门铁克),申请一年,不支持通配符,有数量限制. ...
- 阿里Java编码规范
详细,全面 很不错 阿里 Java编码规范
- office2013 激活方式
1.下载 KMSpico_setup 2.关闭所有杀毒 3.打开 KMSpico_setup.exe 安装,下一步下一步,完成 4.打开word2013看下还有没弹出过期,没有即成功 5.卸载k ...
- SqlParameter防止SQL注入
SQL注入的解决方案有好几种,待我细细研究过之后逐一讲解. 方法一:SqlParameter方法 这里有一篇博客是详细介绍SqlParameter的,可以看看 点我 string sqlStr=&qu ...
- numpy中的arg系列函数
numpy中的arg系列函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me 不定期更新,现学现卖 numpy中arg系列函数被经常使用,通常先进行排序然后返回原数组特定的索引. argmax ...
- 在ajax请求后台时在请求标头RequestHeader加token
情景:为了保证系统数据的安全性,一般前后台之间的数据访问会有授权与验证,这里的Token机制相对于Cookie支持跨域访问,在RESTful API里面,验证一般可以使用POST请求来通过验证,使服务 ...
- bzoj千题计划175:bzoj1303: [CQOI2009]中位数图
http://www.lydsy.com/JudgeOnline/problem.php?id=1303 令c[i]表示前i个数中,比d大的数与比d小的数的差,那么如果c[l]=c[r],则[l+1, ...
- Myeclipse 工具优化 [内存一直增加, jsp,javascript 编辑很卡]
首先看这篇随笔 地址: Myeclipse/STS 首次在本地部署配置一个Spring MVC 项目 (十二) [http://www.cnblogs.com/editor/p/3915239.htm ...
- Spring Mvc 一个接口多个继承; (八)
在 spring 注解实现里,一个接口一般是不能多继承的! 除非在 bean 配置文件里有 针对这个 实现类的配置: <beans:bean id="icService" c ...