KOT
KOT

Reputation: 2116

AWS Cloudformation modify resolv.conf in EC2 instance

I want to add a custom search entry to the /etc/resolv.conf file in my EC2 instances when they start up.

I use Cloudformation to provision my servers. The file is already populated with one search entry by AWS so I just want to add a second entry to this line, like so:

search myCompany.com region.compute.internal

What is the best way to achieve this using cloudformation?

Upvotes: 2

Views: 800

Answers (1)

Jose Haro Peralta
Jose Haro Peralta

Reputation: 999

With the user data parameter: that will do all necessary modifications to your instance at launch time. In your instance definition in the CloudFormation script, add something like this:

  MyEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      UserData:
        Fn::Base64: !Sub |
          #!/bin/bash
          echo "search myCompany.com region.compute.internal" >> /etc/resolv.conf

Upvotes: 1

Related Questions