Search code examples
jsonamazon-web-servicescommand-line-interfaceelastic-load-balancer

Backup and restore AWS load balancers


We have several AWS test environments with LoadBalancers. This cost a lot of money as LoadBalancers can not be turned off. I therefor tries to create a script to Back them of and restore them. I tryed this:

aws elb describe-load-balancers --load-balancer-name testLB --output json > .\testLB.json

This gives a json file but when i try create a new form that file i though I'd just

aws elb create-load-balancer  --cli-input-json file://testLB.json

but then i get a long error like

C:\code\AWS-Scripts\LoadbalancerScript [master ≡ +1 ~0 -0 | +6 ~1 -0 !]> aws elb create-load-balancer  --cli-input-json file://test3.json

Error parsing parameter 'cli-input-json': Invalid JSON: No JSON object could be decoded JSON received:  ■{

     " L o a d B a l a n c e r D e s c r i p t i o n s " :   [

             {

                     " S u b n e t s " :   [

                             " s u b n e t - 1 2 3 4 5 a b c "

                     ] ,

                     " C a n o n i c a l H o s t e d Z o n e N a m e I D " :   " 1 2 3 4 5 a b c d e f g h 6 " ,

and the wired spacing diapers if i change the file from UCS-2-LE BOM to UTF 8 bit it still does not parse:

Error parsing parameter 'cli-input-json': Invalid JSON: No JSON object could be decoded JSON received: test3.json

Any idea?

UPDATE Tryed to use --generate-cli-skeleton and then

aws elb create-load-balancer --cli-input-json file://C:\code\AWS-Scripts     \LoadbalancerScript\lbSkeleton.json

But that returned:

Error parsing parameter 'cli-input-json': Invalid JSON: No JSON object could be decoded
JSON received: {
"LoadBalancerName": "testBalancer",
"Listeners": [
    {
        "InstancePort": 8003,
        "LoadBalancerPort": 8003,
        "Protocol": "HTTP",
        "InstanceProtocol": "HTTP"
    },
],
"AvailabilityZones": [
    "eu-central-1b"
],
"Subnets": [
    "subnet-123123123"
],
"SecurityGroups": [
    "sg-123123",
    "sg-123123"
],
"Scheme": "",
"Tags": [
    {
        "Key": "Environment",
        "Value": "123123"
    }
]

}

Plz help


Solution

  • You should be looking at using CloudFormation template to launch and turn off any AWS Resources. Cloudformer is helpful for creating templates for existing resources.


    If you still need to use the CLI, you can generate CLI Skeleton JSON that outlines all of the parameters that can be specified for the operation. you can then fill up the values and then create the load balancers

    aws elb create-load-balancer --generate-cli-skeleton

    {
        "LoadBalancerName": "",
        "Listeners": [
            {
                "Protocol": "",
                "LoadBalancerPort": 0,
                "InstanceProtocol": "",
                "InstancePort": 0,
                "SSLCertificateId": ""
            }
        ],
        "AvailabilityZones": [
            ""
        ],
        "Subnets": [
            ""
        ],
        "SecurityGroups": [
            ""
        ],
        "Scheme": "",
        "Tags": [
            {
                "Key": "",
                "Value": ""
            }
        ]
    }