svdgraaf / serverless-fargate-tasks

Run Fargate tasks within your serverless project
43 stars 21 forks source link

TypeError: Cannot read property 'Properties' of undefined #2

Closed debttestbot closed 5 years ago

debttestbot commented 5 years ago

I just tried using this plugin from the examples in the README:

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           9.5.0
     Serverless Version:     1.38.0

serverless-fargate-tasks version: 0.1.0

serverless.yml:

service: serverless-test

plugins:
  - serverless-fargate-tasks

custom:
  fargate:
    network:
      public-ip: DISABLED
      subnets:
        - subnet-00
        - subnet-01
    tasks:
      my-task:
        image: alpine:3.8

provider:
  name: aws
  stage: dev
  region: us-east-1

Error:

Fargate Tasks Plugin
Processing my-task

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

  Cannot read property 'Properties' of undefined

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

  Stack Trace --------------------------------------------

TypeError: Cannot read property 'Properties' of undefined
    at Object.keys.forEach.identifier (/Users/bgibbs/secops/git_python/node_modules/serverless-fargate-tasks/lib/index.js:54:54)
    at Array.forEach (<anonymous>)
    at ServerlessFargateTasks.compileTasks (/Users/bgibbs/secops/git_python/node_modules/serverless-fargate-tasks/lib/index.js:37:32)
    at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:407:55)

I'm fairly new to working with the serverless framework, so I'm hoping that I'm just missing a config option somewhere?

ptrhck commented 5 years ago

I am having the same issue, it would be great to see a full working serverless.yml example!

samlevine commented 5 years ago

The plugin is looking for options.vpc, rather than options.network in the documentation. Your config should hopefully work just by changing network to vpc under custom, fargate.

That said, if the documentation is what is desired I took the liberty of making a pull request to make the plugin match it:

https://github.com/svdgraaf/serverless-fargate-tasks/pull/1

ptrhck commented 5 years ago

Changing to vpc in serverless.yml does not resolve the issue. The same error occurs.

mrcai commented 5 years ago

@ptrhck It's trying to get properties for IamRoleLambdaExecution but that doesn't exist. This could be because you don't have a Lambda function declared in your serverless.yml. I've resolved this by declaring a lambda function.

svdgraaf commented 5 years ago

@ptrhck @mrcai is correct, Fargate needs an iam role to function. This plugin re-uses the one created by the serverless framework. Unfortunately, this also means there needs to be at least 1 lambda function present, because Serverless framework doesn't create the IAM role when no function is present (which is understandable, but perhaps a bit odd).

I'll close this issue, the solution is to add at least 1 lambda function (it can be empty of course).

thomas-bc commented 4 years ago

My use case was to not create any IAM role with Serverless because of company policy. I got around this issue by using the override option documented here (Advanced usage) and specifying the ARN of the existing IAM role I wanted Fargate to use.

svdgraaf commented 4 years ago

Thanks @thomas-bc that's a perfect solution!