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. JVM学习笔记(四):类加载机制

    虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验.转换解析和初始化,最终形成可以被虚拟机直接使用的Java类型,这就是虚拟机的类加载机制. 一.类加载的时机1. 类从被加载到虚拟机内存 ...

  2. MT【175】刚刚凑巧

    已知$\Delta ABC$满足$\sin^2A+\sin^2B+\sin^2C=2\sqrt{3}\sin A\sin B\sin C,a=2$,求$A$ 提示:利用正弦定理:$a^2+b^2+c^ ...

  3. 解题:NOI 2010 航空管制

    题面 常见的套路与不常见的套路 第一问是常见的套路,建反边用优先队列跑拓扑排序 第二问是不常见的套路,如何判断一个点最早什么时候起飞?先不加它来拓扑排序,直到拓扑排序不能进行下去了,这个时刻就是它必须 ...

  4. C#基础概念

    1.     面向对象的思想主要包括:继承 多态 封装 ●       封装:用抽象的数据类型将数据和基于数据的操作封装在一起,数据被保护在抽象数据类型内部. ●       继承:子类拥有父类的所有 ...

  5. Nagios服务器端配置文件详解

    Nagios服务器端安装部署详解见:http://www.cnblogs.com/ginvip/p/6505948.html Nagios 主要用于监控一台或者多台本地主机及远程的各种信息,包括本机资 ...

  6. springSecurity自定义认证配置

    上一篇讲了springSecurity的简单入门的小demo,认证用户是在xml中写死的.今天来说一下自定义认证,读取数据库来实现认证.当然,也是非常简单的,因为仅仅是读取数据库,权限是写死的,因为相 ...

  7. Ubuntu 16.04开机自启Nginx简单脚本

    本文要记述的是最简单的Ubuntu下开机自启 nginx的脚本 这里将nginx装在了/usr/local/nginx目录下,nginx本身没有注册成服务,所以直接使用服务开机自启是不行的,除非自己写 ...

  8. spring框架学习(三)spring与junit整合测试

    package cn.mf.b_test; import javax.annotation.Resource; import org.junit.Test; import org.junit.runn ...

  9. Asp.net 子web application的Session共享

    需求提出: 网站: 父Web Application: http://www.test.com/ 子Web Application 1: http://www.test.com/child1 子Web ...

  10. [整理]JS中的状态机

    /*StateMachine*/ var StateMachine = (function(){ function StateMachine(opts){ this.current = opts.in ...