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. 【题解】第n小的数

    题目描述 给你一些整数,你要找出第n小的数,也就是说把数据按升序排序后,输出下标是n的那个数,注意,我们规定下标是从0开始的.但是我们给出的数据的格式比较奇怪,我们是按区间给出,例如:给出两个区间:[ ...

  2. IDEA导出jar包后运行报错 找不到或无法加载主类

    开发工具:IDEA16 运行环境:ubuntu 问题:根据网上的Idea导出jar包的方法,将我的项目导出jar包后运行报错:找不到或无法加载主类.   为了找到这个原因,我重新搭建了一个测试例子,在 ...

  3. 【刷题】BZOJ 3512 DZY Loves Math IV

    Description 给定n,m,求 模10^9+7的值. Input 仅一行,两个整数n,m. Output 仅一行答案. Sample Input 100000 1000000000 Sampl ...

  4. Python【unittest】模块

    [unittest]模块是python3.5中的一个内置模块 1.python文件导入[unittest]模块 import unittest 2.定义一个测试用例类,继承[unittest.Test ...

  5. Java基础-标识符与关键字

    Java基础-标识符与关键字 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是标识符 标识符就是程序员在编写程序时,给类,变量,方法等起的名字. 二.标识符的命名规则 1& ...

  6. 【前端安全】JavaScript防XSS攻击

    什么是XSS XSS(Cross Site Scripting),跨站脚本攻击,是一种允许攻击者在另外一个用户的浏览器中执行恶意代码脚本的脚本注入式攻击.本来缩小应该是CSS,但为了和层叠样式(Cas ...

  7. jdk1.8.0_45源码解读——Map接口和AbstractMap抽象类的实现

    jdk1.8.0_45源码解读——Map接口和AbstractMap抽象类的实现 一. Map架构 如上图:(01) Map 是映射接口,Map中存储的内容是键值对(key-value).(02) A ...

  8. Java SpringMVC框架学习(二)httpServeltRequest和Model传值的区别

    HttpServletRequest 为什么大多程序在controller中给jsp传值时使用model.addAttribute()而不使用httpServeletRequest.setAttrib ...

  9. 获取web页面xpath

    1. Open Chrome 2. Right click the element that you want to get xpath 3. select "Inspector" ...

  10. js 奇葩技巧之隐藏代码

    昨天在群看到有人发了个文章叫<“短”化你的代码>,思路非常不错,采用unicode的零宽字符来实现字符隐藏,虽然有字符,可是你却看不见它.这篇文章详细的介绍了这种方法的实现原理,最后还给出 ...