Search code examples
dslcloud-hosting

Is there a dsl for AWS EC2?


I am looking at using Amazon cloud services (EC2, S3 etc) for hosting. I've been looking at the JSON metadata that can be specified to configure various instances and the complexity has me concerned. Is there a dsl that will generate valid JSON metadata and more importantly validate the entries?


Solution

  • Unfortunately, I drew a blank after searching for this recently. I'm using Amazon Web Services CloudFormation (is that the JSON metadata you're talking about?).

    There are a couple of issues with CloudFormation JSON files:

    1. I'm at well over 1,500 lines and it's impossible to read,
    2. You can't express everything the API gives you, notably in the area of Virtual Private Clouds,
    3. There are lots of bugs that are taking a long time to fix, Elastic Load Balancers losing HTTPS information, for example.

    So I've been using straight-up API calls in Scala using the Java API. It's actually really nice.

    The Java API has a flavor of "setters" starting with with that return this so they can be chained. In Scala, you can use these to act like a poor-man's DSL. So you can do things like

    val updateRequest = new UpdateAutoScalingGroupRequest()
                        .withAutoScalingGroupName(group.getAutoScalingGroupName)
                        .withAvailabilityZones(subnetAZsOfOurVPC)
                        .withVPCZoneIdentifier(subnetNamesOfOurVPC)
    
    as.updateAutoScalingGroup(updateRequest)
    

    Other things are easy to do in Scala with the Java API. For example, group all your Subnets by VPC in a Map, simply do

    val subnetsByVPC = ec2.describeSubnets(new DescribeSubnetsRequest).getSubnets.groupBy(_.getVpcId)