-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Bug Report : Not be able to use Fn::ImportValue or Ref in the Authorizer section of a File in *.YAML File #3129
Comments
Seems that the problem in principle stems from using "arn" field for both pointing to a function for custom authorizer, and to point to a cognito user pool. |
I tried the above approach and it works. That is - I changed the code to use However, I think there needs to be a discussion about how to do this, as there are multiple options. Couple that I can think of:
|
adds poolarn parameter to the authorizer section for api gateway. to be used when specifying 'arn' parameter is not sufficient for determining if the reference is an authorizer function or cognito user pool. Specifically that is the case when Fn:ImportValue is used.
* fix-for-serverless#3129: use poolarn , instead of arn for the cognito user pool
Closing...please check the comment in the PR for explanation |
Can we open this again? It's impacting me right now and I don't feel there is proper resolution. IMHO the schema under
|
@ProTip thanks for reaching out. 👍 Were you able to solve this problem somehow? If so, how did you do it? Or are you striving for an easier way to configure it? |
I worked around this by encoding information into the naming schema. However, I believe that the configuration should be more consistent. "Ref" and "Fn::GetAtt" are the idiomatic way to link resources together with AWS CloudFormation; this should be supported throughout the config IMHO. Otherwise there are surprises; like again today with the SNS topic arn not able to be Ref'd. |
Hi guys, I worked around this by using cloud formation output in environment variable. authorizer:
arn: ${self:provider.environment.USERPOOL_ARN} Then in your environment variables : environment:
STACK_NAME: ${self:service}-${opt:stage, self:provider.stage}
USERPOOL_ARN: ${cf:${self:provider.environment.STACK_NAME}.UserPoolArn} And in your cloud formation outputs : Outputs:
UserPoolArn:
Value:
'Fn::GetAtt': [ UserPool, Arn ] |
@aymericaitamer I attempted to use this solution, but I had to let the UserPool be created first. After the first deployment, I could add the authorizer and environment variables. Was that the intended function of your solution? Thanks! |
I am having the same issue/ The following environment parameter of a function :
Passes to the function as: |
I have the same issue with set
that actualy work... not super but it's working... that not work for me :
|
This worked for me, basically you need to name the authorizer to make it work hello-world:
handler: hello-world.handler
events:
- http:
path: /hello-world
authorizer:
name: SharedAuthorizer
arn:
'Fn::ImportValue': ${self:provider.stage}-SharedAuthorizer |
When I try the above syntax, I get this error on the first line of the next function that is defined in the template: |
I tried adding a name as well and it doesn't work. I get the functionArn.split is not a function error |
This still is an issue but specifying it like this seems to solve it
|
Not be able to use Fn::ImportValue or Ref in the Authorizer section of a File in *.YAML File
Description
Hi, It seems we found a bug. The scenario is as follows :
We defined a custom authorizer lambda function in a Cloudformation (stack A) and we exposed the ARN of the lambda function as an Output resource (Export name is "CustomAuthorizerDefaultFunction").
In the following Yml file which is located in a different Cloudformation stack (Stack B), we are going to Fn::ImportValue from cloudformation stack A. As we commented in the following Yaml file :
1- 'Fn::ImportValue': 'CustomAuthorizerDefaultFunction' works fine in the Resources-> Output section.
2- 'Fn::ImportValue': 'CustomAuthorizerDefaultFunction' does not work when we use it in Authorizer section of the function.
3- 'Fn::ImportValue': 'CustomAuthorizerDefaultFunction' works in the environment section of a function definition.
4- Also Besides 'Fn::ImportValue', Ref: AuthorizerArnImport does not work either.
Any thought ? If it is a known issue, any suggestions ?
Thanks
------------------------------------------------------ part of our Yml File----------------
service: usvc-dmp-rest
frameworkVersion: ">=1.0.0 <2.0.0"
plugins:
provider:
profile: serverless-admin
name: aws
runtime: nodejs4.3
memorySize: 128
resources:
Outputs:
AuthorizerArnImport:
Description: 'Authorizer Arn'
Value:
'Fn::ImportValue': 'CustomAuthorizerDefaultFunction'
functions:
myFunction:
handler: 'app/endpoints/myFunction/handler.myFunctionHandler'
environment:
MY_THING:
Works
Fails
arn:
Ref: AuthorizerArnImport
Works
arn: "arn:aws:lambda:us-east-1:xxxxxxx:function:CustomAuthorizer-DefaultFunction-1BT9PWQLLI7GI"
Fails?
Serverless Framework Version you're using:
Stack Trace:
TypeError: functionArn.split is not a function
at Object.extractAuthorizerNameFromArn (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\lib\naming.js:110:34)
at AwsCompileApigEvents.getAuthorizer (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\compile\events\apiGateway\lib\validate.js:204:37)
at _.forEach (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\compile\events\apiGateway\lib\validate.js:50:36)
at arrayEach (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\lodash\lodash.js:537:11)
at Function.forEach (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\lodash\lodash.js:9344:14)
at _.forEach (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\compile\events\apiGateway\lib\validate.js:42:9)
at C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\lodash\lodash.js:4970:15
at baseForOwn (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\lodash\lodash.js:3020:24)
at C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\lodash\lodash.js:4939:18
at Function.forEach (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\lodash\lodash.js:9344:14)
at AwsCompileApigEvents.validate (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\compile\events\apiGateway\lib\validate.js:41:7)
at deploy:compileEvents (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deploy\compile\events\apiGateway\index.js:42:31)
at BbPromise.reduce (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\lib\classes\PluginManager.js:160:50)
at tryCatcher (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\util.js:16:23)
at Object.gotValue (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\reduce.js:157:18)
at Object.gotAccum (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\reduce.js:144:25)
at Object.tryCatcher (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:510:31)
at Promise._settlePromise (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:567:18)
at Promise._settlePromise0 (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:612:10)
at Promise._settlePromises (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\promise.js:691:18)
at Async._drainQueue (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:138:16)
at Async._drainQueues (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:148:10)
at Immediate.Async.drainQueues (C:\Users\KamroozN\AppData\Roaming\npm\node_modules\serverless\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:649:20)
at tryOnImmediate (timers.js:622:5)
at processImmediate [as _immediateCallback] (timers.js:594:5)
Your Environment Information -----------------------------
OS: win32
Node Version: 6.9.3
Serverless Version: 1.5.0
The text was updated successfully, but these errors were encountered: