Posts

Showing posts from 2019

Use Instance Store With AWS Elastic Container Storage

Many EC2 instance types come with instance attached storage (Instance Store) which can provide a fast local storage that is faster than using an EBS volume. If your using the Amazon ECS-optimized AMI (Amazon Linux 1), it’s instance storage is a secondary EBS volume that is used for storing docker containers and volumes. If your launching it on an EC2 with instance store, it is ignored and only the one EBS volume is used. So here is a simplistic cloud-init script that detects the attached SSD and NVMe SSD’s and adds them to the LVM volume group.
Note: I have not done thorough performance testing but have noticed a slight increase in IO times when configured this way on the newer generation (i.e. c5d, r5d etc) types.Just launch your EC2 instance with the following user data or download the script from this gist if you’ve got a more complex init script already.EC2 User Data#cloud-boothook set -ex # find ephemeral devices using the metadata service # note: this will block loading until t…

Create a Private Microservice Using an Application Load Balancer

Image
Previously if you wanted to create an REST API powered by a lambda you only had one choice: API Gateway. This has a few limitations notably they’re always public so you need to use IAM or similar to lock it down and you can only use a custom domain name once globally, meaning no duplicating the implementations across multiple accounts with the same host endpoint. AWS recently announced another way to create a RESTful endpoint for Lambda’s: Application Load Balancers.

Using an async iterator on Node.js + S3

There isn't support for async iterators (for await...of) in Node.js v8.9 which is AWS Lambda's runtime. It's shame, as it’s a great feature that allows you to iterate over an iterable that returns as result asynchronously, i.e. retrieving another page from a database, using a compact for loop that feels synchronous but under the covers is actually done asynchronously.
Which means, if you want to use a library that written specifically to use it (e.g. Amazon DynamoDB QueryPaginator), you have to use an even more verbose syntax. However with a bit of re-purposing you can use a generator function that returns a Promise and if you await each promise given in the loop it will behave like an async iterator.