Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Govcloud custom resource fix #6996

Merged
merged 7 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/plugins/aws/customResources/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,22 @@ 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-1') {
awsNode = 'aws-us-gov';
}
return `arn:${awsNode}:lambda:${region}:${accountId}:function:${functionName}`;
jmb12686 marked this conversation as resolved.
Show resolved Hide resolved
}

function getEnvironment(context) {
jmb12686 marked this conversation as resolved.
Show resolved Hide resolved
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],
Expand Down
54 changes: 54 additions & 0 deletions lib/plugins/aws/customResources/resources/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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',
});
});
});