Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
afterAll(async () => {
await SNS.deleteTopic({ TopicArn: snsTopicArn }).promise();
try {
const permissionParams = {
FunctionName: consumerName,
StatementId: `${ruleName}Permission`
};
await lambda().removePermission(permissionParams).promise();
} catch (err) {
// If the deletion test passed, this _should_ fail. This is just handling
// the case where the deletion test did not properly clean this up.
}
});
async addKinesisEventSource(item, lambda) {
// use the existing event source mapping if it already exists and is enabled
const listParams = {
FunctionName: lambda.name,
EventSourceArn: item.rule.value
};
const listData = await aws.lambda().listEventSourceMappings(listParams).promise();
if (listData.EventSourceMappings && listData.EventSourceMappings.length > 0) {
const currentMapping = listData.EventSourceMappings[0];
// This is for backwards compatibility. Mappings should no longer be disabled.
if (currentMapping.State === 'Enabled') {
return currentMapping;
}
return aws.lambda().updateEventSourceMapping({
UUID: currentMapping.UUID,
Enabled: true
}).promise();
}
// create event source mapping
const params = {
EventSourceArn: item.rule.value,
FunctionName: lambda.name,
StartingPosition: 'TRIM_HORIZON',
Enabled: true
};
return aws.lambda().createEventSourceMapping(params).promise();
}
async addKinesisEventSource(item, lambda) {
// use the existing event source mapping if it already exists and is enabled
const listParams = {
FunctionName: lambda.name,
EventSourceArn: item.rule.value
};
const listData = await aws.lambda().listEventSourceMappings(listParams).promise();
if (listData.EventSourceMappings && listData.EventSourceMappings.length > 0) {
const currentMapping = listData.EventSourceMappings[0];
// This is for backwards compatibility. Mappings should no longer be disabled.
if (currentMapping.State === 'Enabled') {
return currentMapping;
}
return aws.lambda().updateEventSourceMapping({
UUID: currentMapping.UUID,
Enabled: true
}).promise();
}
// create event source mapping
const params = {
EventSourceArn: item.rule.value,
Protocol: 'lambda',
Endpoint: process.env.messageConsumer,
ReturnSubscriptionArn: true
};
const r = await aws.sns().subscribe(subscriptionParams).promise();
subscriptionArn = r.SubscriptionArn;
}
// create permission to invoke lambda
const permissionParams = {
Action: 'lambda:InvokeFunction',
FunctionName: process.env.messageConsumer,
Principal: 'sns.amazonaws.com',
SourceArn: item.rule.value,
StatementId: `${item.name}Permission`
};
await aws.lambda().addPermission(permissionParams).promise();
return subscriptionArn;
}
return currentMapping;
}
return aws.lambda().updateEventSourceMapping({
UUID: currentMapping.UUID,
Enabled: true
}).promise();
}
// create event source mapping
const params = {
EventSourceArn: item.rule.value,
FunctionName: lambda.name,
StartingPosition: 'TRIM_HORIZON',
Enabled: true
};
return aws.lambda().createEventSourceMapping(params).promise();
}
async deleteSnsTrigger(item) {
// delete permission statement
const permissionParams = {
FunctionName: process.env.messageConsumer,
StatementId: `${item.name}Permission`
};
await aws.lambda().removePermission(permissionParams).promise();
// delete sns subscription
const subscriptionParams = {
SubscriptionArn: item.rule.arn
};
return aws.sns().unsubscribe(subscriptionParams).promise();
}
async function getLambdaAliases(lambdaFunctionName) {
const config = {
MaxItems: 10000,
FunctionName: lambdaFunctionName
};
return getAllPages(config, 'Aliases', lambda().listAliases.bind(lambda()));
}
.action((cmd) => {
if (!cmd.migrationVersion) {
throw new Error('version argument is missing');
}
if (!cmd.stack) {
throw new Error('stack name is missing');
}
const l = lambda();
console.log(`Invoking migration: ${cmd.migrationVersion}`);
l.invoke({
FunctionName: `${cmd.stack}-executeMigrations`,
Payload: `{ "migrations": ["${cmd.migrationVersion}"] }`
}).promise().then(console.log).catch(console.error);
});
async deleteKinesisEventSource(item, eventType) {
if (await this.isEventSourceMappingShared(item, eventType)) {
return undefined;
}
const params = {
UUID: item.rule[this.eventMapping[eventType]]
};
return aws.lambda().deleteEventSourceMapping(params).promise();
}