API timeouts in AWS Lambda?

戏子无情 提交于 2020-01-05 08:22:13

问题


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

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?


回答1:


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.



来源:https://stackoverflow.com/questions/47078759/api-timeouts-in-aws-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!