Marc Iskander
Marc Iskander

Reputation: 187

I am trying to create an ECS service in cloudformation, and I want to use the default VPC that it creates, and choose any of the subnets

Below is the yaml template. In the NetworkConfiguration, the subnet property is required. How should I set it to be any subnet of the default VPC that was created?

Resources:
    ECSService:
        Type: AWS::ECS::Service
        Properties:
            TaskDefinition: !Ref ECSTaskDefinition
            LaunchType: FARGATE
            Cluster: !Ref ECSCluster
            ServiceName: !Join
                - '-'
                - 
                    - !Ref Message
                    - !Ref Stage
                    - service
            DesiredCount: 1
            DeploymentConfiguration:
                MaximumPercent: 200
                MinimumHealthyPercent: 100
            NetworkConfiguration:
                AwsvpcConfiguration:
                    AssignPublicIp: ENABLED
                    Subnets: 
                        - ?????

Upvotes: 2

Views: 519

Answers (2)

krunal shimpi
krunal shimpi

Reputation: 1

If it is a default vpc, you could try hardcoding the values. Or defined an new vpc and subnets in your template and refer to them.

Btw you can try cloudkast which is an online aws cloudformation template generator. It should make your life less dreadful while dealing with cloudformation templates. ;-)

Upvotes: 0

NHol
NHol

Reputation: 2125

There isn’t a value for “any subnet in this vpc”, you’d have to set the subnets in the template or as a parameter.

Alternatively you can create the vpc and subnets in the template and reference them when describing your ECS service.

Lastly you could use a custom resource to call a Lambda function that looks up the subnets but it’s more complicated than a native reference. See an AWS blog post on it here https://aws.amazon.com/blogs/mt/looking-up-information-on-aws-cloudformation-stack-parameters-using-aws-lambda/

Upvotes: 1

Related Questions