https://serverless-stack.com/ logo
#help
Title
# help
j

John

03/02/2022, 9:25 PM
so I got my first AWS bill 😄 Only 20euro but it was a surprise as I'm just playing around with an idea on SST. I am using a subaccount of my main account so I don't qualify for the free tier. The thing that cost all the money is Amazon Elastic Compute Cloud NatGateway. I'm going to close the subaccount and work on my main account but is there anyway to reduce the NAT Gateway usage/cost?
r

Ross Coundon

03/02/2022, 9:26 PM
Do you need to run your code inside a VPC? If not, you can ditch the NAT Gateway. Otherwise, take a look at fck-nat
j

John

03/02/2022, 9:34 PM
Thanks
I think I need a VPC - db with api gateway and lambda
fck-nat looks great, thanks
r

Ross Coundon

03/02/2022, 9:39 PM
@thdxr knows more about it than me but you may be able to use the data api with your dB and have your lambda outside a VPC
t

thdxr

03/02/2022, 9:43 PM
Yeah the nat is killer! We have a way to avoid it if you have some flexibility though. The new sst.RDS construct spins up a serverless RDS instance. It creates its own VPC without a nat gateway. Lambdas don't need to be in it because they can talk to it through the data-api (sql over http secured by IAM) We recommend kysely as a slick typescript client for it along with our kysely-data-api library
j

John

03/02/2022, 9:52 PM
Thanks guys, is there an example anywhere that I can have a look at on how to set this up?
f

Frank

03/03/2022, 5:58 AM
@John if you just did this, SST creates a new VPC without NAT
Copy code
new RDS(this, "Database", {
  engine: "postgresql10.14",
  defaultDatabaseName: "my_database",
});
When SST creates the VPC for RDS, it only creates
Public
and
Isolated
subnets. You can read more about the subnet types here https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2-readme.html#subnet-types
j

John

03/03/2022, 7:14 AM
Thank you
2 Views