1

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?

Mark B
  • 183,023
  • 24
  • 297
  • 295
user7862512
  • 273
  • 1
  • 9

1 Answers1

5

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295