diff --git a/lib/plugins/aws/customResources/resources/utils.js b/lib/plugins/aws/customResources/resources/utils.js index 8166d6752..abf638df7 100644 --- a/lib/plugins/aws/customResources/resources/utils.js +++ b/lib/plugins/aws/customResources/resources/utils.js @@ -56,13 +56,24 @@ function response(event, context, status, data = {}, err) { } function getLambdaArn(region, accountId, functionName) { - return `arn:aws:lambda:${region}:${accountId}:function:${functionName}`; + let awsNode = 'aws'; + if(region === 'us-gov-west-1' || region === 'us-gov-east-2') { + awsNode = 'aws-us-gov'; + } + return `arn:${awsNode}:lambda:${region}:${accountId}:function:${functionName}`; } function getEnvironment(context) { - const arn = context.invokedFunctionArn.match( - /^arn:aws.*:lambda:(\w+-\w+-\d+):(\d+):function:(.*)$/ - ); + let arn; + if (context.invokedFunctionArn.includes("arn:aws-us-gov")) { + arn = context.invokedFunctionArn.match( + /^arn:aws-us-gov.*:lambda:(\w+-\w+-\w+-\d+):(\d+):function:(.*)$/ + ); + } else { + arn = context.invokedFunctionArn.match( + /^arn:aws.*:lambda:(\w+-\w+-\d+):(\d+):function:(.*)$/ + ); + } return { LambdaArn: arn[0], Region: arn[1], diff --git a/lib/plugins/aws/customResources/resources/utils.test.js b/lib/plugins/aws/customResources/resources/utils.test.js index f9c4cf698..c5e20c54d 100644 --- a/lib/plugins/aws/customResources/resources/utils.test.js +++ b/lib/plugins/aws/customResources/resources/utils.test.js @@ -15,6 +15,28 @@ describe('#getLambdaArn()', () => { }); }); +describe('#getLambdaArn() govloud west', () => { + it('should return the govcloud Lambda arn', () => { + const region = 'us-gov-west-1'; + const accountId = '123456'; + const functionName = 'some-function'; + const arn = getLambdaArn(region, accountId, functionName); + + expect(arn).to.equal('arn:aws-us-gov:lambda:us-gov-west-1:123456:function:some-function'); + }); +}); + +describe('#getLambdaArn() govcloud east', () => { + it('should return the govcloud Lambda arn', () => { + const region = 'us-gov-east-1'; + const accountId = '123456'; + const functionName = 'some-function'; + const arn = getLambdaArn(region, accountId, functionName); + + expect(arn).to.equal('arn:aws-us-gov:lambda:us-gov-east-1:123456:function:some-function'); + }); +}); + describe('#getEnvironment()', () => { it('should return an object with information about the execution environment', () => { const context = { @@ -30,3 +52,35 @@ describe('#getEnvironment()', () => { }); }); }); + +describe('#getEnvironment() govcloud east', () => { + it('should return an object with information about the govcloud execution environment', () => { + const context = { + invokedFunctionArn: 'arn:aws-us-gov:lambda:us-gov-east-1:123456:function:some-function', + }; + const env = getEnvironment(context); + + expect(env).to.deep.equal({ + LambdaArn: 'arn:aws-us-gov:lambda:us-gov-east-1:123456:function:some-function', + Region: 'us-gov-east-1', + AccountId: '123456', + LambdaName: 'some-function', + }); + }); +}); + +describe('#getEnvironment() govcloud west', () => { + it('should return an object with information about the govcloud execution environment', () => { + const context = { + invokedFunctionArn: 'arn:aws-us-gov:lambda:us-gov-west-1:123456:function:some-function', + }; + const env = getEnvironment(context); + + expect(env).to.deep.equal({ + LambdaArn: 'arn:aws-us-gov:lambda:us-gov-west-1:123456:function:some-function', + Region: 'us-gov-west-1', + AccountId: '123456', + LambdaName: 'some-function', + }); + }); +});