CloudFormation template error

Hi, I’m trying to create a lambda function using a DynamoDB stream as an input event. The DynamoDB table and stream were created outside of Serverless, using a different account.

If I try to deploy the first time I get the error below, I can deploy a second time and it says it is successful but if I check the AWS console I see no lambda function but the code gets deployed into an S3 bucket and the CloudFormation stack successfully completes.

To work around this issue, I manually create the Lambda using the AWS console and point to the zip created by Serverless in S3. The function works as expected.

The error:

sls deploy --stage dev
Serverless: Parsing Python requirements.txt
Serverless: Installing required Python packages for runtime python3.6...
Serverless: Linking required Python packages...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Unlinking required Python packages...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.....
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (2.29 MB)...
Serverless: Validating template...
 
  Error --------------------------------------------------
 
  The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource items
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Stack Trace --------------------------------------------
 
Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource items
    at provider.request.catch (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:25:13)
From previous event:
    at AwsDeploy.validateTemplate (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:20:12)
From previous event:
    at AwsDeploy.BbPromise.bind.then (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:117:39)
From previous event:
    at Object.aws:deploy:deploy:validateTemplate [as hook] (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:113:10)
    at BbPromise.reduce (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/classes/PluginManager.js:236:55)
From previous event:
    at PluginManager.invoke (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/classes/PluginManager.js:236:22)
    at PluginManager.spawn (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/classes/PluginManager.js:248:17)
    at AwsDeploy.BbPromise.bind.then (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:91:48)
From previous event:
    at Object.deploy:deploy [as hook] (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:87:10)
    at BbPromise.reduce (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/classes/PluginManager.js:236:55)
From previous event:
    at PluginManager.invoke (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/classes/PluginManager.js:236:22)
    at PluginManager.run (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/classes/PluginManager.js:255:17)
    at variables.populateService.then (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/Serverless.js:99:33)
    at runCallback (timers.js:666:20)
    at tryOnImmediate (timers.js:639:5)
    at processImmediate [as _immediateCallback] (timers.js:611:5)
From previous event:
    at Serverless.run (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/lib/Serverless.js:86:74)
    at serverless.init.then (/Users/ymaalo/.nvm/versions/node/v6.10.2/lib/node_modules/serverless/bin/serverless:39:50)
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless
 
  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           6.10.2
     Serverless Version:     1.19.0

The serverless.yml is as follows:

service: elasticsearch

provider:
  name: aws
  runtime: python3.6
  role: arn:aws:iam::063414442810:role/serverless-lambda-full
  stage: dev


package:
  exclude:
    - test.py

plugins:
  - serverless-python-requirements

custom: ${file(secrets.${opt:stage, self:provider.stage}.yml)}

functions:
  process:
    handler: es_handler.process_stream
    events:
      - stream:
          type: dynamodb
          arn:
            Fn::GetAtt:
              - items
              - StreamArn
    environment:
      ES_ENDPOINT: ${self:custom.ES_ENDPOINT}
      REGION: ${self:custom.REGION}

Any idea what’s going on?

UPDATE: I’ve solved this by just using the latest Stream ARN found in the AWS console. I guess the resource has to be specified in the serverless.yml and we can’t refer to resources created outside of Serverless (via the ‘reference to the ARN of a resource by logical ID’ method). Though I’ll test that theory out later.

Your conclusion is correct.

A current limitation is that event sources need to be created as part of the service. There are some issues being discussed about how to get around this, but it’s not a simple problem.

As you mentioned also, the CFN intrinsic functions only work on resources in the current template.

Thank you, I just searched and saw that my guess was right and was about to update.