Create AWS cache clusters in VPC with CloudFormation


I am creating an AWS stack inside a VPC using CloudFormation and need to create ElastiCache clusters on it. I have investigated and there is no support in CloudFormation to create cache clusters in VPCs.
Our “workaround” was to to create the cache cluster when some “fixed” instance (like a bastion for example) bootstrap using CloudInit and AWS AmazonElastiCacheCli tools (elasticache-create-cache-subnet-group, elasticache-create-cache-cluster). Then, when front end machines bootstrap (we are using autoscaling), they use elasticache-describe-cache-clusters to get cache cluster nodes and update configuration.

I would like to know if you have different solutions to this problem.


You workaround is a reasonable one (and shows that you seem to be in control of your AWS operations already).

You could improve on your custom solution eventually by means of the dedicated CustomResource type, which are special AWS CloudFormation resources that provide a way for a template developer to include resources in an AWS CloudFormation stack that are provided by a source other than Amazon Web Services. – the AWS CloudFormation Custom Resource Walkthrough provides a good overview of what this is all about, how it works and what’s required to implement your own.

The benefit of using this facade for a custom resource (i.e. the Amazon ElastiCache cluster in your case) is that its entire lifecycle (create/update/delete) can be handled in a similar and controlled fashion just like any officially supported CloudFormation resource types, e.g. resource creation failures would be handled transparently from the perspective of the entire stack.

However, for the use case at hand you might actually just want to wait for official support becoming available:

We want every EC2 user to be able to benefit from the advanced networking and other features of Amazon VPC that I outlined above. To enable this, starting soon, instances for new AWS customers (and existing customers launching in new Regions) will be launched into the “EC2-VPC” platform. […]

You don’t need to create a VPC beforehand – simply launch EC2
instances or provision Elastic Load Balancers, RDS databases, or
ElastiCache clusters
like you would in EC2-Classic and we’ll create a
VPC for you at no extra charge. We’ll launch your resources into that
VPC […] [emphasis mine]

  • This update sort of implies that any new services will likely be also available in VPC right away going forward (else the new EC2-VPC platform wouldn’t work automatically for new customers as envisioned).
  • Accordingly I’d expect the CloudFormation team to follow suit and complete/amend their support for deployment to VPC going forward as well.

    Leave a Reply