Skip to content

Instantly share code, notes, and snippets.

@tylr
Created July 16, 2016 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylr/848c10630bd3c49b6f6db2269c186142 to your computer and use it in GitHub Desktop.
Save tylr/848c10630bd3c49b6f6db2269c186142 to your computer and use it in GitHub Desktop.
ember-cli-deploy integration with dynamodb
import AWS from 'aws-sdk'
import Promise from 'bluebird'
const env = global.env.env
const ddb = new AWS.DynamoDB({ region: 'us-east-1' })
const TableName = global.env.dynamodb.TableName
const revisionPrefix = global.env.revisionPrefix
const revisionEnv = env === 'development' ? 'beta' : env
export default ({ revision = null } = {}) => {
if(revision) {
return getRevision(revision)
} else {
return getCurrentRevisionId().then(getRevision)
}
}
function getCurrentRevisionId() {
return new Promise((resolve, reject) => {
const params = {
TableName,
Key: {
id: { S: `${revisionPrefix}${revisionEnv}` }
}
}
ddb.getItem(params, (error, response) => {
if(error) {
reject(error)
} else {
resolve(response.Item.value.S.replace(revisionPrefix, ''))
}
})
})
}
function getRevision(revision) {
return new Promise((resolve, reject) => {
const params = {
TableName,
Key: {
id: { S: `${revisionPrefix}${revision}` }
}
}
ddb.getItem(params, (error, response) => {
if(error) {
reject(error)
} else {
resolve(response.Item.value.S.toString('utf8'))
}
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment