from troposphere import (
    Parameter,
    Ref,
)

from troposphere.ecs import (
    Cluster,
)

from .template import template


container_instance_type = Ref(template.add_parameter(Parameter(
    "ContainerInstanceType",
    Description="The container instance type",
    Type="String",
    Default="t2.micro",
    AllowedValues=["t2.micro", "t2.small", "t2.medium"]
)))


template.add_mapping("ECSRegionMap", {
    "eu-west-1": {"AMI": "ami-4e6ffe3d"},
    "us-east-1": {"AMI": "ami-8f7687e2"},
    "us-west-2": {"AMI": "ami-84b44de4"},
})


# ECS cluster
cluster = Cluster(
    "Cluster",
    template=template,
)

from troposphere import (
    iam,
    Parameter,
    Ref,
)

from troposphere.ecs import (
    Cluster,
)

from .template import template


container_instance_type = Ref(template.add_parameter(Parameter(
    "ContainerInstanceType",
    Description="The container instance type",
    Type="String",
    Default="t2.micro",
    AllowedValues=["t2.micro", "t2.small", "t2.medium"]
)))


template.add_mapping("ECSRegionMap", {
    "eu-west-1": {"AMI": "ami-4e6ffe3d"},
    "us-east-1": {"AMI": "ami-8f7687e2"},
    "us-west-2": {"AMI": "ami-84b44de4"},
})


# ECS cluster
cluster = Cluster(
    "Cluster",
    template=template,
)


# ECS container role
container_instance_role = iam.Role(
    "ContainerInstanceRole",
    template=template,
    AssumeRolePolicyDocument=dict(Statement=[dict(
        Effect="Allow",
        Principal=dict(Service=["ec2.amazonaws.com"]),
        Action=["sts:AssumeRole"],
    )]),
    Path="/",
    Policies=[
    ]
)


# ECS container instance profile
container_instance_profile = iam.InstanceProfile(
    "ContainerInstanceProfile",
    template=template,
    Path="/",
    Roles=[Ref(container_instance_role)],
)

Add an instance profile for container instances
Add an instance profile for container instances

  from troposphere import (
+     iam,
      Parameter,
      Ref,
  )
  
  from troposphere.ecs import (
      Cluster,
  )
  
  from .template import template
  
  
  container_instance_type = Ref(template.add_parameter(Parameter(
      "ContainerInstanceType",
      Description="The container instance type",
      Type="String",
      Default="t2.micro",
      AllowedValues=["t2.micro", "t2.small", "t2.medium"]
  )))
  
  
  template.add_mapping("ECSRegionMap", {
      "eu-west-1": {"AMI": "ami-4e6ffe3d"},
      "us-east-1": {"AMI": "ami-8f7687e2"},
      "us-west-2": {"AMI": "ami-84b44de4"},
  })
  
  
  # ECS cluster
  cluster = Cluster(
      "Cluster",
      template=template,
  )
  
+ 
+ # ECS container role
+ container_instance_role = iam.Role(
+     "ContainerInstanceRole",
+     template=template,
+     AssumeRolePolicyDocument=dict(Statement=[dict(
+         Effect="Allow",
+         Principal=dict(Service=["ec2.amazonaws.com"]),
+         Action=["sts:AssumeRole"],
+     )]),
+     Path="/",
+     Policies=[
+     ]
+ )
+ 
+ 
+ # ECS container instance profile
+ container_instance_profile = iam.InstanceProfile(
+     "ContainerInstanceProfile",
+     template=template,
+     Path="/",
+     Roles=[Ref(container_instance_role)],
+ )
+ 
Add an instance profile for container instances
## Code Before:
from troposphere import (
    Parameter,
    Ref,
)

from troposphere.ecs import (
    Cluster,
)

from .template import template


container_instance_type = Ref(template.add_parameter(Parameter(
    "ContainerInstanceType",
    Description="The container instance type",
    Type="String",
    Default="t2.micro",
    AllowedValues=["t2.micro", "t2.small", "t2.medium"]
)))


template.add_mapping("ECSRegionMap", {
    "eu-west-1": {"AMI": "ami-4e6ffe3d"},
    "us-east-1": {"AMI": "ami-8f7687e2"},
    "us-west-2": {"AMI": "ami-84b44de4"},
})


# ECS cluster
cluster = Cluster(
    "Cluster",
    template=template,
)

## Instruction:
Add an instance profile for container instances
## Code After:
from troposphere import (
    iam,
    Parameter,
    Ref,
)

from troposphere.ecs import (
    Cluster,
)

from .template import template


container_instance_type = Ref(template.add_parameter(Parameter(
    "ContainerInstanceType",
    Description="The container instance type",
    Type="String",
    Default="t2.micro",
    AllowedValues=["t2.micro", "t2.small", "t2.medium"]
)))


template.add_mapping("ECSRegionMap", {
    "eu-west-1": {"AMI": "ami-4e6ffe3d"},
    "us-east-1": {"AMI": "ami-8f7687e2"},
    "us-west-2": {"AMI": "ami-84b44de4"},
})


# ECS cluster
cluster = Cluster(
    "Cluster",
    template=template,
)


# ECS container role
container_instance_role = iam.Role(
    "ContainerInstanceRole",
    template=template,
    AssumeRolePolicyDocument=dict(Statement=[dict(
        Effect="Allow",
        Principal=dict(Service=["ec2.amazonaws.com"]),
        Action=["sts:AssumeRole"],
    )]),
    Path="/",
    Policies=[
    ]
)


# ECS container instance profile
container_instance_profile = iam.InstanceProfile(
    "ContainerInstanceProfile",
    template=template,
    Path="/",
    Roles=[Ref(container_instance_role)],
)
