remove getPartition function. Pass partition in thru handler

This commit is contained in:
jmb12686 2019-11-25 07:44:15 -05:00
parent 80b47d0b8c
commit 67d84780bd
8 changed files with 7 additions and 48 deletions

View File

@ -25,6 +25,7 @@ function create(event, context) {
addPermission({
functionName: FunctionName,
userPoolName: UserPoolName,
partition: Partition,
region: Region,
accountId: AccountId,
userPoolId: userPool.Id,

View File

@ -1,7 +1,6 @@
'use strict';
const Lambda = require('aws-sdk/clients/lambda');
const { getPartition } = require('../../utils');
function getStatementId(functionName, userPoolName) {
const normalizedUserPoolName = userPoolName.toLowerCase().replace(/[.:*\s]/g, '');
@ -13,9 +12,8 @@ function getStatementId(functionName, userPoolName) {
}
function addPermission(config) {
const { functionName, userPoolName, region, accountId, userPoolId } = config;
const { functionName, userPoolName, partition, region, accountId, userPoolId } = config;
const lambda = new Lambda({ region });
const partition = getPartition(region);
const params = {
Action: 'lambda:InvokeFunction',
FunctionName: functionName,

View File

@ -30,6 +30,7 @@ function create(event, context) {
return addPermission({
functionName: FunctionName,
partition: Partition,
region: Region,
accountId: AccountId,
eventBus: EventBridgeConfig.EventBus,

View File

@ -2,7 +2,6 @@
const AWS = require('aws-sdk');
const { getEventBusName } = require('./utils');
const { getPartition } = require('../../utils');
function getStatementId(functionName, ruleName) {
const normalizedRuleName = ruleName.toLowerCase().replace(/[.:*]/g, '');
@ -14,9 +13,8 @@ function getStatementId(functionName, ruleName) {
}
function addPermission(config) {
const { functionName, region, accountId, eventBus, ruleName } = config;
const { functionName, partition, region, accountId, eventBus, ruleName } = config;
const lambda = new AWS.Lambda({ region });
const partition = getPartition(region);
let SourceArn = `arn:${partition}:events:${region}:${accountId}:rule/${ruleName}`;
if (eventBus) {
const eventBusName = getEventBusName(eventBus);

View File

@ -24,6 +24,7 @@ function create(event, context) {
return addPermission({
functionName: FunctionName,
bucketName: BucketName,
partition: Partition,
region: Region,
}).then(() =>
updateConfiguration({

View File

@ -1,7 +1,6 @@
'use strict';
const AWS = require('aws-sdk');
const { getPartition } = require('../../utils');
function getStatementId(functionName, bucketName) {
const normalizedBucketName = bucketName.replace(/[.:*]/g, '');
@ -13,9 +12,8 @@ function getStatementId(functionName, bucketName) {
}
function addPermission(config) {
const { functionName, bucketName, region } = config;
const { functionName, bucketName, partition, region } = config;
const lambda = new AWS.Lambda({ region });
const partition = getPartition(region);
const payload = {
Action: 'lambda:InvokeFunction',
FunctionName: functionName,

View File

@ -73,16 +73,6 @@ function getEnvironment(context) {
};
}
function getPartition(region) {
let partition = 'aws';
if (region && /^cn-/.test(region)) {
partition = 'aws-cn';
} else if (region && /^us-gov-/.test(region)) {
partition = 'aws-us-gov';
}
return partition;
}
function handlerWrapper(handler, PhysicalResourceId) {
return (event, context, callback) => {
// extend the `event` object to include the PhysicalResourceId
@ -105,7 +95,6 @@ module.exports = {
response,
getEnvironment,
getLambdaArn,
getPartition,
handlerWrapper,
wait,
};

View File

@ -2,7 +2,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const { expect } = require('chai');
const { getLambdaArn, getEnvironment, getPartition } = require('./utils');
const { getLambdaArn, getEnvironment } = require('./utils');
describe('#getLambdaArn()', () => {
it('should return the Lambda arn', () => {
@ -119,30 +119,3 @@ describe('#getEnvironment() china region', () => {
});
});
});
describe('#getPartition() public', () => {
it('should return the partition for public region', () => {
const region = 'us-east-1';
const partition = getPartition(region);
expect(partition).to.equal('aws');
});
});
describe('#getPartition() china', () => {
it('should return the partition for china region', () => {
const region = 'cn-north-1';
const partition = getPartition(region);
expect(partition).to.equal('aws-cn');
});
});
describe('#getPartition() govcloud', () => {
it('should return the partition for govcloud region', () => {
const region = 'us-gov-west-1';
const partition = getPartition(region);
expect(partition).to.equal('aws-us-gov');
});
});