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. Linux命令行上传本地文件到服务器 、 下载服务器文件到本地

    sh使用命令: scp 将本地文件上传至服务器 第一个是本地文件的路径/文件名, 例如 ./index.tar.gz  . index.html . bg.png 等 第二个是要上传到的服务器的位置  ...

  2. Educational Codeforces Round 38 (Rated for Div. 2) C

    C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. POJ 1062 昂贵的聘礼(最短路中等题)

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 51879   Accepted: 15584 Descripti ...

  4. oracle 创建表空间 与创建用户与分配用户权限

    创建一个表空间名为ABC create tablespace "ABC"     //貌似要大写 datafile 'D:\oracle\TBSPACES\ABC.dbf'   / ...

  5. 【题解】 bzoj1923: [Sdoi2010]外星千足虫 (线性基/高斯消元)

    bzoj1923,戳我戳我 Solution: 这个高斯消元/线性基很好看出来,主要是判断在第K 次统计结束后就可以确定唯一解的地方和\(bitset\)的骚操作 (我用的线性基)判断位置,我们可以每 ...

  6. python里使用正则表达式的非贪婪模式

    在正则表达式里,什么是正则表达式的贪婪与非贪婪匹配 如:String str="abcaxc"; Patter p="ab*c"; 贪婪匹配:正则表达式一般趋向 ...

  7. 什么是Flume

    1.什么是Flume FLUME 是HADOOP生态圈中的一个组件.主要应用于实时数据的流处理,比如一旦有某事件触发(如本地交易引起的数据改动)可以将实时的日志数据发向HADOOP文件系统HDFS中 ...

  8. 【bzoj2754】 SCOI2012—喵星球上的点名

    http://www.lydsy.com/JudgeOnline/problem.php?id=2754 (题目链接) 题意 给出$n$个名字串,$m$个点名串,问对于每一个姓名串,它包含多少个点名串 ...

  9. 简单的sql分组统计

    一个记录员工打卡时间的表,只有两个有效字段 员工名称,打卡时间,现在要统计某一天中,每个员工的打卡次数.最早打卡时间.最晚打卡时间,问sql怎么写? 其实这个sql很简单, 1.首先要明确既然是按每个 ...

  10. SQL优化:索引的重要性

    开篇小测验 下面这样一个小SQL 你该怎么样添加最优索引 两个表上现在只有聚集索引 bigproduct 表上已经有聚集索引 ProductID bigtransactionhistory 表上已经有 ...