1

I am currently improving the deployment process of our service. In particular, I want to update the revision stored in the opsworks CustomJson stack property as soon as we have deployed a new one.

For this I created a new task in our rakefile. Here is the code:

desc "update revision in custom json of stack"
task :update_stack_revision, [:revision, :stack_id] do |t, arg|
  revision = arg[:revision]
  stack_id = arg[:stack_id]

  # get stack config
  stack_description = `aws opsworks \
    --region us-east-1 \
    describe-stacks \
    --stack-id #{stack_id}`

  # get the json config
  raw_custom_json = JSON.parse(stack_description)["Stacks"][0]["CustomJson"]

  # make it parseable by removing invalid chararcters
  raw_custom_json = raw_custom_json.gsub(/(\\n)/, '')
  raw_custom_json = raw_custom_json.gsub(/(\\")/, '"')

  # parse json and update revision
  parsed_custom_json = JSON.parse(raw_custom_json)
  parsed_custom_json["git"]["revision"] = revision

  # transform updated object back into json and bring it into a format required by aws opsworks
  updated_json = JSON.generate(parsed_custom_json)
  updated_json = updated_json.gsub('"', '\"')

  # send update
  `aws opsworks \
    --region us-east-1 \
    update-stack \
    --stack-id #{stack_id} \
    --custom-json "#{updated_json}"`
end

During this process $ characters are lost for some reason.
I tried reproducing this error by executing each command individually. Apparently the last one - aws opsworks update-stack - is at fault here. I'd really like to know why and how to stop this.

zetain
  • 361
  • 4
  • 15

0 Answers0