The Wayback Machine - https://web.archive.org/web/20210816120350/https://github.com/serverless/serverless/issues/9723
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

TypeError: Cannot read property 'Fn::GetAtt' of undefined #9723

Open
chris-hinds opened this issue Jul 8, 2021 · 6 comments · May be fixed by #9727
Open

TypeError: Cannot read property 'Fn::GetAtt' of undefined #9723

chris-hinds opened this issue Jul 8, 2021 · 6 comments · May be fixed by #9727

Comments

@chris-hinds
Copy link

@chris-hinds chris-hinds commented Jul 8, 2021

Running sls deploy --stage dev when using !ImportValue is raising the following TypeError;

TypeError: Cannot read property 'Fn::GetAtt' of undefined

The service that I am deploying is importing an output of another stack. This stack has already been deployed. There is only a single occurrence of Fn::GetAtt and it is in the stack that is already deployed. If I remove the !ImportValue the stack deploys fine.

Running with SLS_DEBUG=* doesn't give any extra info

serverless.yml

Stack I am trying to deploy now

projectDir: ../
useDotenv: true
stage: dev # Default stage

plugins:
  - serverless-offline
  - serverless-bundle
  - serverless-domain-manager

package:
  individually: true

custom:
  bundle: ${file(../commonServerlessConfig.yml):bundle}
  apiDomain: ${file(../commonServerlessConfig.yml):apiDomain}
  customDomain: ${file(../commonServerlessConfig.yml):customDomain}

provider:
  name: aws
  region: ${file(../commonServerlessConfig.yml):region}
  runtime: ${file(../commonServerlessConfig.yml):runtime}
  memorySize: ${file(../commonServerlessConfig.yml):memorySize}
  timeout: ${file(../commonServerlessConfig.yml):timeout}
  versionFunctions: ${file(../commonServerlessConfig.yml):versionFunctions}
  apiGateway: ${file(../commonServerlessConfig.yml):apiGateway}
  

functions:
  organisationEventHandler:
    handler: organisationEventHandler/index.organisationEventHandler
    name: organisations-event-handler
    description: Organisations event handler
    events:
      - sqs: !ImportValue OrganisationsQueueArn

Stack that makes use of Fn::GetAtt (this has already been deployed)


provider:
  name: aws
  region: eu-west-1
  stackName: ****-api-gateway

resources:
  Resources:
    ****ApiGW:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: ****ApiGW

  Outputs:
    apiGatewayRestApiId:
      Value:
        Ref: ****ApiGW
      Export:
        Name: ****ApiGateway-restApiId

    apiGatewayRestApiRootResourceId:
      Value:
        Fn::GetAtt:
          - ****ApiGW
          - RootResourceId
      Export:
        Name: ****ApiGateway-rootResourceId
sls deploy --stage dev output
Serverless: Copying existing artifacts...
Serverless: Packaging service...

 Type Error ----------------------------------------------

  TypeError: Cannot read property 'Fn::GetAtt' of undefined
      at /Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/sqs.js:61:33
      at /Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/sqs.js:70:15
      at Array.forEach (<anonymous>)
      at /Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/sqs.js:44:28
      at Array.forEach (<anonymous>)
      at AwsCompileSQSEvents.compileSQSEvents (/Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/sqs.js:34:47)
      at PluginManager.invoke (/Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/classes/PluginManager.js:576:20)
      at async PluginManager.spawn (/Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/classes/PluginManager.js:598:5)
      at async Object.before:deploy:deploy [as hook] (/Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/plugins/deploy.js:60:11)
      at async PluginManager.invoke (/Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/classes/PluginManager.js:576:9)
      at async PluginManager.run (/Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/classes/PluginManager.js:634:7)
      at async Serverless.run (/Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/lib/Serverless.js:441:5)
      at async /Users/chinds/.nvm/versions/node/v14.15.5/lib/node_modules/serverless/scripts/serverless.js:745:9

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.15.5
     Framework Version:         2.51.1
     Plugin Version:            5.4.3
     SDK Version:               4.2.3
     Components Version:        3.13.3

Installed version

Framework Core: 2.51.1
Plugin: 5.4.3
SDK: 4.2.3
Components: 3.13.3
@medikoo
Copy link
Member

@medikoo medikoo commented Jul 8, 2021

@chris-hinds great thanks for reporting.

Indeed as check, our handling of CF intrinsic function looks broken:

if (typeof event.sqs === 'object') {
EventSourceArn = event.sqs.arn;

PR with a fix is welcome!

@chris-hinds
Copy link
Author

@chris-hinds chris-hinds commented Jul 8, 2021

@chris-hinds great thanks for reporting.

Indeed as check, our handling of CF intrinsic function looks broken:

if (typeof event.sqs === 'object') {
EventSourceArn = event.sqs.arn;

PR with a fix is welcome!

Brill, thanks for getting back to me so fast. I'll take a look shortly.

@chris-hinds
Copy link
Author

@chris-hinds chris-hinds commented Jul 9, 2021

PR for the fix: #9727

it might not be pretty but it fixes this exact bug. Serverless was setting EventSourceArn to undefined with the following serverless config;

events:
      - sqs: !ImportValue OrganisationsQueueArn

Serveless sees this as an object and it expected it to have a key of arn. This PR checks to see if a key of arn exists before setting EventSourceArn if it does not exist it just sets EventSourceArn to the event.sqs object

@pgrzesik
Copy link
Member

@pgrzesik pgrzesik commented Jul 12, 2021

Hello @chris-hinds - could you please post full output of the error that you're getting? I believe in addition to such error, you should also get schema validation warnings that the provided syntax is not supported. Also, it's already possible to reference ARNs of existing queues with CF functions as shown here: https://www.serverless.com/framework/docs/providers/aws/events/sqs/, though it's a bit more verbose. I think we might still consider supporting CF functions passed directly as value of sqs event, but the proposed PR needs a bit more polishing.

@medikoo What do you think - should we still support passing CF functions directly as value of sqs while we currently support that use case via sqs.arn notation?

@medikoo
Copy link
Member

@medikoo medikoo commented Jul 13, 2021

@medikoo What do you think - should we still support passing CF functions directly as value of sqs while we currently
support that use case via sqs.arn notation?

@pgrzesik I think currently by schema, we support both ARN input as intrinsic function directly to SQS event, and when input at arn property (it's the reason I've outlined that we probably have a bug).

Still, you raise a valid point, which I didn't think through well., Indeed to avoid clutter, it seems better to support intrinsic functions only at arn property. and for direct sqs input only support ARN string - and this kind of support is reflected by implementation.

In light of that I would just fix our schema, so we support awsArnString definition as top level.

@pgrzesik
Copy link
Member

@pgrzesik pgrzesik commented Jul 13, 2021

Ah right, I've checked incorrectly and believed that we support only awsArnString directly but that's not the case - given that I'm also leaning towards adjusting the schema to only accept awsArnString as top level and use sqs.arn notation to pass arn as CF intrinsic functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants