Skip to content

Commit

Permalink
fix: Support differet AWS partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 20, 2019
1 parent 9236929 commit f353144
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ class AwsCompileCognitoUserPoolEvents {
if (funcUsesExistingCognitoUserPool) {
iamRoleStatements.push({
Effect: 'Allow',
Resource: `arn:aws:lambda:*:*:function:${FunctionName}`,
Resource: {
'Fn::Sub': `arn:\${AWS::Partition}:lambda:*:*:function:${FunctionName}`,
},
Action: ['lambda:AddPermission', 'lambda:RemovePermission'],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ describe('AwsCompileCognitoUserPoolEvents', () => {
{
Action: ['lambda:AddPermission', 'lambda:RemovePermission'],
Effect: 'Allow',
Resource: 'arn:aws:lambda:*:*:function:first',
Resource: { 'Fn::Sub': 'arn:${AWS::Partition}:lambda:*:*:function:first' },
},
]);
expect(Resources.FirstCustomCognitoUserPool1).to.deep.equal({
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('AwsCompileCognitoUserPoolEvents', () => {
{
Action: ['lambda:AddPermission', 'lambda:RemovePermission'],
Effect: 'Allow',
Resource: 'arn:aws:lambda:*:*:function:first',
Resource: { 'Fn::Sub': 'arn:${AWS::Partition}:lambda:*:*:function:first' },
},
]);
expect(Resources.FirstCustomCognitoUserPool1).to.deep.equal({
Expand Down Expand Up @@ -557,7 +557,7 @@ describe('AwsCompileCognitoUserPoolEvents', () => {
{
Action: ['lambda:AddPermission', 'lambda:RemovePermission'],
Effect: 'Allow',
Resource: 'arn:aws:lambda:*:*:function:first',
Resource: { 'Fn::Sub': 'arn:${AWS::Partition}:lambda:*:*:function:first' },
},
{
Action: [
Expand All @@ -571,7 +571,7 @@ describe('AwsCompileCognitoUserPoolEvents', () => {
{
Action: ['lambda:AddPermission', 'lambda:RemovePermission'],
Effect: 'Allow',
Resource: 'arn:aws:lambda:*:*:function:second',
Resource: { 'Fn::Sub': 'arn:${AWS::Partition}:lambda:*:*:function:second' },
},
]);
expect(Object.keys(Resources)).to.have.length(2);
Expand Down
16 changes: 12 additions & 4 deletions lib/plugins/aws/package/compile/events/eventBridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class AwsCompileEventBridgeEvents {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{ Ref: 'AWS::Region' },
{ Ref: 'AWS::AccountId' },
`rule/${RuleName}`,
Expand All @@ -125,7 +127,9 @@ class AwsCompileEventBridgeEvents {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{ Ref: 'AWS::Region' },
{ Ref: 'AWS::AccountId' },
`event-bus/${eventBusName}`,
Expand All @@ -136,7 +140,9 @@ class AwsCompileEventBridgeEvents {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{ Ref: 'AWS::Region' },
{ Ref: 'AWS::AccountId' },
`rule/${eventBusName}/${RuleName}`,
Expand Down Expand Up @@ -178,7 +184,9 @@ class AwsCompileEventBridgeEvents {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{ Ref: 'AWS::Region' },
{ Ref: 'AWS::AccountId' },
'function',
Expand Down
68 changes: 51 additions & 17 deletions lib/plugins/aws/package/compile/events/eventBridge/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -155,7 +157,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{
Ref: 'AWS::Region',
},
Expand Down Expand Up @@ -246,7 +250,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -270,7 +276,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -289,7 +297,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{
Ref: 'AWS::Region',
},
Expand Down Expand Up @@ -385,7 +395,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -409,7 +421,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -428,7 +442,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{
Ref: 'AWS::Region',
},
Expand Down Expand Up @@ -517,7 +533,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -541,7 +559,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -560,7 +580,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{
Ref: 'AWS::Region',
},
Expand Down Expand Up @@ -652,7 +674,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -671,7 +695,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{
Ref: 'AWS::Region',
},
Expand Down Expand Up @@ -762,7 +788,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -781,7 +809,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{
Ref: 'AWS::Region',
},
Expand Down Expand Up @@ -876,7 +906,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:events',
'arn',
{ Ref: 'AWS::Partition' },
'events',
{
Ref: 'AWS::Region',
},
Expand All @@ -895,7 +927,9 @@ describe('AwsCompileEventBridgeEvents', () => {
'Fn::Join': [
':',
[
'arn:aws:lambda',
'arn',
{ Ref: 'AWS::Partition' },
'lambda',
{
Ref: 'AWS::Region',
},
Expand Down

0 comments on commit f353144

Please sign in to comment.