Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
shouldDeploy(prevInstance) {
const inputs = {
document: this.document
}
const prevInputs = prevInstance ? pick(keys(inputs), prevInstance) : {}
const configChanged = not(equals(inputs, prevInputs))
// make sure any added suffix from prevInstance is preserved
// otherwise name will always be different
if (prevInstance && this.policyName === `policy-${this.instanceId}`) {
this.policyName = prevInstance.policyName
}
// if config changed, change the name to trigger replace
if (prevInstance && configChanged && this.policyName.includes(`policy-${this.instanceId}`)) {
this.policyName = `policy-${this.instanceId}-${Math.random()
.toString(36)
.substring(7)}`
}
// if the user changed the config without changing the name, error!
if (prevInstance && configChanged && prevInstance.policyName === this.policyName) {
arn: 'arn:aws:iam::aws:policy/AdministratorAccess'
}
const policy = this.policy || defaultPolicy
if (!prevInstance) {
context.log(`Creating Role: ${roleName}`)
this.arn = await createRole(IAM, {
roleName,
service: this.service,
policy
})
} else {
if (prevInstance.service !== this.service) {
await updateAssumeRolePolicy(IAM, this)
}
if (!equals(prevInstance.policy, policy)) {
await detachRolePolicy(IAM, this)
await attachRolePolicy(IAM, this)
}
}
}
shouldDeploy(prevInstance) {
if (!prevInstance) {
return 'deploy'
}
const inputs = {
topic: this.topic,
protocol: this.protocol,
endpoint: this.endpoint,
subscriptionAttributes: this.subscriptionAttributes
}
const prevInputs = prevInstance ? pick(keys(inputs), prevInstance) : {}
const configChanged = not(equals(inputs, prevInputs))
if (
not(equals(prevInstance.protocol, inputs.protocol)) ||
not(equals(prevInstance.topic, inputs.topic))
) {
return 'replace'
} else if (configChanged) {
return 'deploy'
}
return undefined
}
shouldDeploy(prevInstance) {
if (!prevInstance) {
return 'deploy'
}
const inputs = pick(inputsProps, this)
const prevInputs = prevInstance ? pick(inputsProps, prevInstance) : {}
const configChanged = not(equals(inputs, prevInputs))
if (not(equals(prevInputs.phoneNumber, inputs.phoneNumber))) {
return 'replace'
} else if (configChanged) {
return 'deploy'
}
return undefined
}
async deploy(prevInstance, context) {
const tableName = get('tableName', this)
if (
prevInstance &&
(not(equals(prevInstance.attributeDefinitions, this.attributeDefinitions)) ||
not(equals(prevInstance.provisionedThroughput, this.provisionedThroughput)) ||
not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes)) ||
not(equals(prevInstance.sseSpecification, this.sseSpecification)) ||
not(equals(prevInstance.streamSpecification, this.streamSpecification)))
) {
context.log(`Updating table: '${tableName}'`)
if (not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes))) {
context.log(
`Skipping GlobalSecondaryIndex updates for table '${tableName}' (currently not supported)`
)
}
await ensureTable(updateTable, this)
context.log(`Table updated: '${tableName}'`)
} else if (
prevInstance &&
not(equals(prevInstance.timeToLiveSpecification, this.timeToLiveSpecification))
) {
context.log(`Updating time to live of the table: '${tableName}'`)
await updateTimeToLive(this)
context.log(`Time to live of the table updated: '${tableName}'`)
} else {
context.log(`Creating table: '${tableName}'`)
const { provider } = this
const AWS = provider.getSdk()
const IAM = new AWS.IAM()
if (!prevInstance || this.roleName !== prevInstance.roleName) {
context.log(`Creating Role: ${this.roleName}`)
this.arn = await createRole(IAM, {
roleName: this.roleName,
service: this.service,
policy: this.policy
})
} else {
if (prevInstance.service !== this.service) {
await updateAssumeRolePolicy(IAM, this)
}
if (!equals(prevInstance.policy, this.policy)) {
await removeRolePolicy(IAM, prevInstance)
await addRolePolicy(IAM, { roleName: this.roleName, policy: this.policy })
}
}
}
async deploy(prevInstance, context) {
const tableName = get('tableName', this)
if (
prevInstance &&
(not(equals(prevInstance.attributeDefinitions, this.attributeDefinitions)) ||
not(equals(prevInstance.provisionedThroughput, this.provisionedThroughput)) ||
not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes)) ||
not(equals(prevInstance.sseSpecification, this.sseSpecification)) ||
not(equals(prevInstance.streamSpecification, this.streamSpecification)))
) {
context.log(`Updating table: '${tableName}'`)
if (not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes))) {
context.log(
`Skipping GlobalSecondaryIndex updates for table '${tableName}' (currently not supported)`
)
}
await ensureTable(updateTable, this)
context.log(`Table updated: '${tableName}'`)
} else if (
prevInstance &&
not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes)) ||
not(equals(prevInstance.sseSpecification, this.sseSpecification)) ||
not(equals(prevInstance.streamSpecification, this.streamSpecification)))
) {
context.log(`Updating table: '${tableName}'`)
if (not(equals(prevInstance.globalSecondaryIndexes, this.globalSecondaryIndexes))) {
context.log(
`Skipping GlobalSecondaryIndex updates for table '${tableName}' (currently not supported)`
)
}
await ensureTable(updateTable, this)
context.log(`Table updated: '${tableName}'`)
} else if (
prevInstance &&
not(equals(prevInstance.timeToLiveSpecification, this.timeToLiveSpecification))
) {
context.log(`Updating time to live of the table: '${tableName}'`)
await updateTimeToLive(this)
context.log(`Time to live of the table updated: '${tableName}'`)
} else {
context.log(`Creating table: '${tableName}'`)
await ensureTable(createTable, this)
context.log(`Table created: '${tableName}'`)
if (this.timeToLiveSpecification) {
context.log(`Updating time to live of the table: '${tableName}'`)
await updateTimeToLive(this)
context.log(`Time to live of the table updated: '${tableName}'`)
}
}
}