1

I am trying to use troposphere to make a cloudformation template. The stack the template makes intended to be a simple example of codedeploy

I have previously got troposphere to generate ec2, s3, iam and route53 generating templates. I have previously made codedeploy work with the GUI AWS Console

I am encountering an error and I don't see why

Here is my troposphere program

    from troposphere import Template
    from troposphere.codedeploy import Application, DeploymentConfig, DeploymentGroup, MinimumHealthyHosts, S3Location


    #1
    #CreateApplication with an applicationName
    app=Application( 'test123')

    #2
    #CreateDeploymentConfig

    config=DeploymentConfig('config123',
                           MinimumHealthyHosts=MinimumHealthyHosts( Type='HOST_COUNT', Value=1 )
                           )

    #3
    #CreateDeploymentGroup using applicationName as input
    #and deploymentConfigName
    depgroup=DeploymentGroup("depgroup123",
                             ApplicationName='test123',
                             DeploymentConfigName='config123', 
                             ServiceRoleArn='arn:aws:iam::930517348825:role/isCompatibleWithAWSCodeDeploy')
)    
    t = Template()
    t.add_description(
    """
    Test of making a code deploy setup from a template
    """)
    t.add_resource(app)
    t.add_resource(config)
    t.add_resource(depgroup)

    print(t.to_json())

Here is the Cloudformation template it makes

{
    "Description": "\nTest of making a code deploy setup from a template\n",
    "Resources": {
        "config123": {
            "Properties": {
                "MinimumHealthyHosts": {
                    "Type": "HOST_COUNT",
                    "Value": 1
                }
            },
            "Type": "AWS::CodeDeploy::DeploymentConfig"
        },
        "depgroup123": {
            "Properties": {
                "ApplicationName": "test123",
                "DeploymentConfigName": "config123",
                "ServiceRoleArn": "arn:aws:iam::930517348825:role/isCompatibleWithAWSCodeDeploy"
            },
            "Type": "AWS::CodeDeploy::DeploymentGroup"
        },
        "test123": {
            "Type": "AWS::CodeDeploy::Application"
        }
    }
}

When I load the template into the cloudformation GUI this occurs before roll back

09:08:50 UTC+0000   CREATE_FAILED   AWS::CodeDeploy::DeploymentConfig   config123   Resource creation cancelled
09:08:48 UTC+0000   CREATE_IN_PROGRESS  AWS::CodeDeploy::DeploymentConfig   config123   
09:08:48 UTC+0000   CREATE_FAILED   AWS::CodeDeploy::DeploymentGroup    depgroup123     No application found for name: test123
09:08:47 UTC+0000   CREATE_COMPLETE     AWS::CodeDeploy::Application    test123     

What I don't understand is that the stack has created the AWS::CodeDeploy::Application "test123" but then the next message says "No application found for name: test123"

role/isCompatibleWithAWSCodeDeploy already exists.
Do I need to add anything else?

Vorsprung
  • 32,923
  • 5
  • 39
  • 63

1 Answers1

2

TLDR

just use Refs:

            "ApplicationName": {"Ref": "test123"},                                                                                                                                                        
            "DeploymentConfigName": {"Ref": "config123"},

Detailed answer

From what I can see from you cf template, the created application doesn't have name. In order for it to have a name the appropriate piece of your cf template should look like this:

    "test123": {                                                                                                                                                                                          
        "Type": "AWS::CodeDeploy::Application",
        "Properties" : {
            "ApplicationName" : "test123"
        }                                                                                                                                                           
    }

The same applyes to config. The config should have DeploymentConfigName property. But even after adding ApplicationName launching may fail. Because your template doesn't guarantee that depgroup is created after application and deploymentconfig.

To guarantee correct order of creation you should use Refs:

{                                                                                                                                                                                                             
    "Description": "\nTest of making a code deploy setup from a template\n",                                                                                                                                  
    "Resources": {                                                                                                                                                                                            
        "config123": {                                                                                                                                                                                        
            "Properties": {                                                                                                                                                                                   
                "MinimumHealthyHosts": {                                                                                                                                                                      
                    "Type": "HOST_COUNT",                                                                                                                                                                     
                    "Value": 1                                                                                                                                                                                
                }                                                                                                                                                                                             
            },                                                                                                                                                                                                
            "Type": "AWS::CodeDeploy::DeploymentConfig"                                                                                                                                                       
        },                                                                                                                                                                                                    
        "depgroup123": {                                                                                                                                                                                      
            "Properties": {                                                                                                                                                                                   
                "ApplicationName": {"Ref": "test123"},                                                                                                                                                        
                "DeploymentConfigName": {"Ref": "config123"},                                                                                                                                                 
                "ServiceRoleArn": "arn:aws:iam::930517348825:role/isCompatibleWithAWSCodeDeploy"                                                                                                                     
            },                                                                                                                                                                                                
            "Type": "AWS::CodeDeploy::DeploymentGroup"                                                                                                                                                        
        },                                                                                                                                                                                                    
        "test123": {                                                                                                                                                                                          
            "Type": "AWS::CodeDeploy::Application"                                                                                                                                                            
        }                                                                                                                                                                                                     
    }                                                                                                                                                                                                         
}
Molecular Man
  • 22,277
  • 3
  • 72
  • 89
  • ApplicationName was missing as a prop for "Application" in the version of troposphere I had. Latest from git fixes this – Vorsprung Jan 06 '16 at 11:13
  • Most useful answer, thanks v much. Now trying to figure out if CodeDeploy does fully work with CloudFormation. ``AWS::CodeDeploy::Deployment`` seems to be be missing or undocumented – Vorsprung Jan 07 '16 at 14:44