mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Fix handling of arns in GovCloud east and west regions
This commit is contained in:
parent
8e022ba3fe
commit
c61dc47f9d
@ -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],
|
||||
|
||||
@ -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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user