Skip to content

Instantly share code, notes, and snippets.

@turhn
Created November 20, 2015 14:14
Show Gist options
  • Save turhn/673fc181d91e37805691 to your computer and use it in GitHub Desktop.
Save turhn/673fc181d91e37805691 to your computer and use it in GitHub Desktop.
AWS Get Last Deployment's Commit Id
#!/usr/bin/env ruby
require 'json'
class Deployments
def initialize(app_name, deployment_group)
@app_name, @deployment_group = app_name, deployment_group
end
def latest_successful_deployments
JSON.parse %x(aws deploy list-deployments \
--deployment-group-name=#{@deployment_group} \
--application-name=#{@app_name} \
--include-only-statuses=Succeeded)
end
def latest_commit
latest_id = latest_successful_deployments["deployments"].first
latest_deployment = JSON.parse %x(aws deploy get-deployment --deployment-id=#{latest_id})
latest_deployment["deploymentInfo"]["revision"]["gitHubLocation"]["commitId"]
end
end
unless ARGV.length == 2
puts 'Usage: lcommitid <ApplicationName> <DeploymentGroup>'
else
d = Deployments.new ARGV[0], ARGV[1]
puts d.latest_commit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment