diff --git a/lib/plugins/aws/customResources/resources/cognitoUserPool/handler.js b/lib/plugins/aws/customResources/resources/cognitoUserPool/handler.js index 51e2805fd..bc74dce0c 100644 --- a/lib/plugins/aws/customResources/resources/cognitoUserPool/handler.js +++ b/lib/plugins/aws/customResources/resources/cognitoUserPool/handler.js @@ -25,6 +25,7 @@ function create(event, context) { addPermission({ functionName: FunctionName, userPoolName: UserPoolName, + partition: Partition, region: Region, accountId: AccountId, userPoolId: userPool.Id, diff --git a/lib/plugins/aws/customResources/resources/cognitoUserPool/lib/permissions.js b/lib/plugins/aws/customResources/resources/cognitoUserPool/lib/permissions.js index d29f3fe36..d88233343 100644 --- a/lib/plugins/aws/customResources/resources/cognitoUserPool/lib/permissions.js +++ b/lib/plugins/aws/customResources/resources/cognitoUserPool/lib/permissions.js @@ -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, diff --git a/lib/plugins/aws/customResources/resources/eventBridge/handler.js b/lib/plugins/aws/customResources/resources/eventBridge/handler.js index 912c9f4bf..cf5dcadb0 100644 --- a/lib/plugins/aws/customResources/resources/eventBridge/handler.js +++ b/lib/plugins/aws/customResources/resources/eventBridge/handler.js @@ -30,6 +30,7 @@ function create(event, context) { return addPermission({ functionName: FunctionName, + partition: Partition, region: Region, accountId: AccountId, eventBus: EventBridgeConfig.EventBus, diff --git a/lib/plugins/aws/customResources/resources/eventBridge/lib/permissions.js b/lib/plugins/aws/customResources/resources/eventBridge/lib/permissions.js index 8e4104709..be4094d33 100644 --- a/lib/plugins/aws/customResources/resources/eventBridge/lib/permissions.js +++ b/lib/plugins/aws/customResources/resources/eventBridge/lib/permissions.js @@ -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); diff --git a/lib/plugins/aws/customResources/resources/s3/handler.js b/lib/plugins/aws/customResources/resources/s3/handler.js index 01a10f7a7..20de80941 100644 --- a/lib/plugins/aws/customResources/resources/s3/handler.js +++ b/lib/plugins/aws/customResources/resources/s3/handler.js @@ -24,6 +24,7 @@ function create(event, context) { return addPermission({ functionName: FunctionName, bucketName: BucketName, + partition: Partition, region: Region, }).then(() => updateConfiguration({ diff --git a/lib/plugins/aws/customResources/resources/s3/lib/permissions.js b/lib/plugins/aws/customResources/resources/s3/lib/permissions.js index 7e8a6c436..60ccd63ee 100644 --- a/lib/plugins/aws/customResources/resources/s3/lib/permissions.js +++ b/lib/plugins/aws/customResources/resources/s3/lib/permissions.js @@ -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, diff --git a/lib/plugins/aws/customResources/resources/utils.js b/lib/plugins/aws/customResources/resources/utils.js index 970fd6e86..e855cd5b6 100644 --- a/lib/plugins/aws/customResources/resources/utils.js +++ b/lib/plugins/aws/customResources/resources/utils.js @@ -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, }; diff --git a/lib/plugins/aws/customResources/resources/utils.test.js b/lib/plugins/aws/customResources/resources/utils.test.js index 5e87ed165..aa42c4eb6 100644 --- a/lib/plugins/aws/customResources/resources/utils.test.js +++ b/lib/plugins/aws/customResources/resources/utils.test.js @@ -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'); - }); -});