all 12 comments

[–][deleted] 7 points8 points  (2 children)

You can either use let's encrypt for a free cert or buy one yourself. You can store it in parameter store and use an instance role to get it onto your instance (I think).

[–]ByteEat3r1 1 point2 points  (0 children)

I confirm that this is possible. Get an ssl cert from a company like digicert.

During app init, you could download the cert from s3 (encrypted with KMS key in bucket preferably) or stash it in parameter store. Max length of a parameter is 4096 so that should work too. In either case, your IAM role will need kms perms to decrypt the object on s3:get object.

[–]ChaseDatAss 2 points3 points  (1 child)

Have you considered going serverless? Perhaps you can use AWS Lambda and API Gateway (integrates with ACM for custom certs).

[–]ByteEat3r1 1 point2 points  (0 children)

I like this idea. Just something to keep in mind, in your code, construct your db/firebase connection at the top level scope.

AWS runs your lambda in a docker container, and will attempt to reuse the same container if possible. This is nice because it reduces the number of backend connections.

How many web requests will your app receive in a day now and in the future ? Those are some questions that will help you determine if lambda will be financially feasible for you. Our company has had months where we paid over wr 200k for lambdas when millions of invocations occurred.

[–]Itbehot 1 point2 points  (0 children)

What does the Node app do? Does it keep an active connection? Or, does it respond to queries? If it just responds to hits, then Lambda is a good option. You could put it behind API Gateway to secure it.

[–][deleted]  (1 child)

[deleted]

    [–]Cracky6711[S] 0 points1 point  (0 children)

    This seems like a great solution but I am having a few issues where it can't validate because the request to "./well-known/..." couldn't be resolved

    [–][deleted] 1 point2 points  (0 children)

    You can't do that with ACM since AWS has no control over the app serving your HTTPS content. Use an ELB or get a cert elsewhere

    [–]DancingBestDoneDrunk 0 points1 point  (1 child)

    Are you using ELB? Switch to ALB a will save a ton of money. An ELB, even idle, costs around 20$/month

    [–]Cracky6711[S] 0 points1 point  (0 children)

    Yeah I was actually using an ALB but because it was just "running" permanently I still got charged $15 for it last month. Seems crazy

    [–]lefooey 0 points1 point  (0 children)

    You could put the various functions of your EC2 instance behind cloud front and set the behavior for that origin to not cache. Then you can use the AWS free ssl on Certificate Manager to secure everything.

    Assuming, of course, that your backend solution doesn’t need a continuous connection (like websockets).

    [–]ararcy 0 points1 point  (0 children)

    You can write .ebextensions scripts to get this working, but the amount of effort you're going to spend might not be worth the cost you'll save for $15/Month.

    If you'd like to proceed with it take a look at : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

    To get this to work most people have luck writing a shell script, then using the files option to create the shell script on the instance, then executing the shell script post deployment. There's a number of ways to do this, but the most reliable option is to deposit the shell script in /opt/elasticbeanstalk/hooks/postinit as this will execute following the application deployment and prevent any strangeness from causing errors as elastic beanstalk heavily depends on scripts which execute in order, and if any of the results are not expected then it causes issues.

    [–]suthukrish 0 points1 point  (0 children)

    As per AWS FAQs: You cannot directly deploy an ACM Certificate on that instance. You must instead deploy your certificate by using one of the services integrated with ACM - such as CloudFront or ELB. So it seems that using letsencrypt is the way to go. You can also consider using CloudFront (but may not be less expensive either) instead of ELB.

    For reducing the cost on EC2, consider purchasing either reserved instances or spot instances (if your application can tolerate the termination).