在AWS Lambda中访问Web [英] Access web within AWS Lambda

查看:154
本文介绍了在AWS Lambda中访问Web的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义一个lambda.当它收到POST请求时,我想向外部uri(例如,splunk或apigee或AWS以外的任何东西)发出另一个POST请求.这可能吗? Lambda是否允许上网?我用谷歌搜索,但没有找到一个很好的答案.

I'd like to define a lambda. When it receives a POST request, I'd like to make another POST request to an external uri (say, splunk or apigee or anything outside of AWS). Is this possible? Does Lambda allow the internet access? I googled but did not find a good answer for this one.

推荐答案

是的,您几乎可以运行任何在普通EC2实例上运行的代码.例如,如果您在node.js中编写Lambda,则可以使用request库对其他Web服务进行HTTP调用.只要您在Lambda中包含要使用的任何库,对于Java或Python都是如此.只需确保将Lambda超时设置得足够高,以使您的呼叫有足够的时间来完成.

Yes, you can run pretty much any code that you would run on a normal EC2 instance. For instance, if you write your Lambda in node.js you can use the request library to make HTTP calls out to other webservices. The same is true of Java or Python as long as you include whatever library you want to use to make the call in your Lambda. Just make sure you set the Lambda timeout high enough to allow your call(s) enough time to complete.

我写了一篇博客文章,显示了一个Lambda调用天气API(HTTP GET)的简单示例,以获取邮政编码的天气并将其发布在Slack中:

I wrote a blog post that shows a simple example of a Lambda calling out to a weather API(HTTP GET) to get weather for a zip code and post it in Slack: http://www.ryanray.me/serverless-slack-integrations

这篇关于在AWS Lambda中访问Web的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆