AWS Lambda中的API超时? [英] API timeouts in AWS Lambda?

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

问题描述

我正在尝试在AWS中创建一个lambda函数,该函数将创建一个新的Stripe令牌:

I'm trying to create a lambda function in AWS which will create a new Stripe token:

import stripePackage from 'stripe';
const stripe = stripePackage('...');

module.exports.create = (event, context, callback) => {
    stripe.tokens.create({
      card: {
        "number": 4242424242424242,
        "exp_month": '02',
        "exp_year": '22',
        "cvc": '123'
      }
    }, (err, token) => {
      if (err) {
        console.log(err);
        callback(null, {
          statusCode: 400,
          body: "error"
        });
      }
      callback(null, {
        statusCode: 200,
        body: "ok"
      });
      console.log(token);
    });
}

但是,这每次都会超时.我有一个用于出站连接的安全组,如下所示:

However, this will time out every time. I have a security group for outbound connections as follows:

 Ports  Destination
 All    0.0.0.0/0

但是,我似乎只能连接到其他AWS服务.如何打开Lambda函数以进行AWS外部的连接?

However the only thing I seem to be able to connect to are other AWS services. How can I open my Lambda function up to connections outside AWS?

推荐答案

您要么需要从VPC中删除Lambda函数(如果不需要访问VPC资源,则将其添加到VPC只会引起性能问题) ,或者您需要确保Lambda函数位于VPC的专用子网中,并且该子网具有到NAT网关的路由.

You either need to remove the Lambda function from your VPC (if it doesn't need VPC resource access then adding it to the VPC only introduces performance issues anyway), or you need to make sure the Lambda function is in a private subnet of your VPC and that subnet has a route to a NAT Gateway.

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

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