|
1 | 1 | 'use strict'; |
| 2 | + |
2 | 3 | const _ = require('lodash'); |
3 | 4 | const BbPromise = require('bluebird'); |
4 | 5 | const path = require('path'); |
@@ -148,27 +149,56 @@ function getLambdaPermissions(state) { |
148 | 149 | // function name can be name-only, name-only with alias, full arn or partial arn |
149 | 150 | // https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestParameters |
150 | 151 | const functionName = state.Parameters.FunctionName; |
151 | | - const segments = functionName.split(':'); |
152 | | - |
153 | | - let functionArn; |
154 | | - if (functionName.startsWith('arn:aws:lambda')) { |
155 | | - // full ARN |
156 | | - functionArn = functionName; |
157 | | - } else if (segments.length === 3 && segments[0].match(/^\d+$/)) { |
158 | | - // partial ARN |
159 | | - functionArn = { |
160 | | - 'Fn::Sub': `arn:aws:lambda:\${AWS::Region}:${functionName}`, |
161 | | - }; |
162 | | - } else { |
163 | | - // name-only (with or without alias) |
164 | | - functionArn = { |
165 | | - 'Fn::Sub': `arn:aws:lambda:\${AWS::Region}:\${AWS::AccountId}:function:${functionName}`, |
166 | | - }; |
| 152 | + if (_.isString(functionName)) { |
| 153 | + const segments = functionName.split(':'); |
| 154 | + |
| 155 | + let functionArn; |
| 156 | + if (functionName.startsWith('arn:aws:lambda')) { |
| 157 | + // full ARN |
| 158 | + functionArn = functionName; |
| 159 | + } else if (segments.length === 3 && segments[0].match(/^\d+$/)) { |
| 160 | + // partial ARN |
| 161 | + functionArn = { |
| 162 | + 'Fn::Sub': `arn:aws:lambda:\${AWS::Region}:${functionName}`, |
| 163 | + }; |
| 164 | + } else { |
| 165 | + // name-only (with or without alias) |
| 166 | + functionArn = { |
| 167 | + 'Fn::Sub': `arn:aws:lambda:\${AWS::Region}:\${AWS::AccountId}:function:${functionName}`, |
| 168 | + }; |
| 169 | + } |
| 170 | + |
| 171 | + return [{ |
| 172 | + action: 'lambda:InvokeFunction', |
| 173 | + resource: functionArn, |
| 174 | + }]; |
| 175 | + } else if (_.has(functionName, 'Fn::GetAtt')) { |
| 176 | + // because the FunctionName parameter can be either a name or ARN |
| 177 | + // so you should be able to use Fn::GetAtt here to get the ARN |
| 178 | + return [{ |
| 179 | + action: 'lambda:InvokeFunction', |
| 180 | + resource: functionName, |
| 181 | + }]; |
| 182 | + } else if (_.has(functionName, 'Ref')) { |
| 183 | + // because the FunctionName parameter can be either a name or ARN |
| 184 | + // so you should be able to use Fn::GetAtt here to get the ARN |
| 185 | + return [{ |
| 186 | + action: 'lambda:InvokeFunction', |
| 187 | + resource: { |
| 188 | + 'Fn::Sub': [ |
| 189 | + 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${FunctionName}', |
| 190 | + { |
| 191 | + FunctionName: functionName, |
| 192 | + }, |
| 193 | + ], |
| 194 | + }, |
| 195 | + }]; |
167 | 196 | } |
168 | 197 |
|
| 198 | + // hope for the best... |
169 | 199 | return [{ |
170 | 200 | action: 'lambda:InvokeFunction', |
171 | | - resource: functionArn, |
| 201 | + resource: functionName, |
172 | 202 | }]; |
173 | 203 | } |
174 | 204 |
|
|
0 commit comments