Your EC2 instances won't have a concept of a "current replication group". So, without knowing the replication group ID, you'll have to determine it yourself. There are a couple different ways of doing it:
Option 1:
In your CloudFormation template, pass the Replication Group ID to your EC2 instance via it's User Data.
Inside your CloudFormation template, you can use { "Ref" : "MyReplicationGroup" }
to get the replication ID of the group to pass into the User Data.
Or you can use { "Fn::GetAtt" : [ "MyReplicationGroup", "PrimaryEndPoint.Address" ] }
to get the primary endpoint's address.
If you're not otherwise using the User Data field of your launch configuration, you can simply reference the ID or endpoint address for the property:
"Properties" : {
"UserData" : { "Ref" : "MyReplicationGroup" },
}
then inside the EC2 instance, grab the user data from the instance meta-data:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-user-data-retrieval
$ curl http://169.254.169.254/latest/user-data
Option 2:
This is not a single command, but you can "find" the replication group:
- From instance meta-data, get the Instance ID
- Use AWS CLI
describe-instances
command to get the tags for your instance.
- Amongst the tags will be a
aws:cloudformation:stack-name
tag which will identify your CloudFormation stack.
- Use the AWS CLI
describe-stack-resources
command to get your stack's resources. In there, find your replication group ID from it's logical CloudFormation ID.