5

I am having cloudformation template which contains two instances with userdata property.

I need to fetch the data from one instance's userdata and pass to another instances userdata.

For example(from below), need to fetch "test" from instance1, and pass to instance2 userdata.

Sample Template:

"instance1": {
  "Type": "AWS::EC2::Instance",
  "Properties": {
"UserData": {
      "Fn::Base64": {
        "Fn::Join": [
          "",
          [
            "#!/bin/bash\n",
            "set -x\n",
            "echo test\n",
          ]]}}}},

"instance2": {
  "Type": "AWS::EC2::Instance",
  "Properties": {
"UserData": {
      "Fn::Base64": {
        "Fn::Join": [
          "",
          [
            "#!/bin/bash\n",
            "set -x\n",
            //fetch the value
          ]]}}}},
2
  • Do you mean that you want to fetch data from instance1 at runtime? (i.e. when the instances are actually running) Commented Feb 28, 2017 at 19:26
  • Thanks for your reply. yes @spg. at the time of provisioning the infrastructure. Commented Mar 1, 2017 at 5:31

1 Answer 1

4

Basically you have 2 options:

  1. Use some sort of a shared memory ( ElastiCache, RDS, S3.... )
  2. scp/ssh directly to another instance and fetch what ever info you need.

I would suggest using shared memory for example S3:

On instance 1:

echo "test" > /tmp/myfile
aws s3 cp /tmp/myfile s3://<bucket>/myfile

On instance 2:

aws s3 cp s3://<bucket>/myfile /tmp/myfile
cat /tmp/myfile
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.