serverless-heaven / serverless-aws-alias

Alias support for Serverless 1.x
MIT License
189 stars 68 forks source link

Unable to deploy simple example containing SNS topic #146

Open psurma opened 5 years ago

psurma commented 5 years ago

Really pulling my hair out with this, so I've gone back to basics and I have the following basic/minimal serverless.yml config:

service: mySimpleService
plugins:
  - serverless-aws-alias
provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-1
functions:
  hello:
    handler: handler.hello

resources:
  Resources:
    PhotoTopic:
      Type: AWS::SNS::Topic
      Properties:
        TopicName: photo-topic-dev
        DisplayName: System

  Outputs:
    PhotoTopicArn:
      Value:
        Ref: PhotoTopic

When attempting to deploy this with serverless deploy it fails with:

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Preparing alias ...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.....
Serverless: Stack create finished...
Serverless: Creating Alias Stack 'dev' ...
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 (387 B)...
Serverless: Validating template...

  Error --------------------------------------------------

  The CloudFormation template is invalid: Unresolved resource dependencies [PhotoTopic] in the Outputs block of the template

     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 -----------------------------
     OS:                     darwin
     Node Version:           8.10.0
     Serverless Version:     1.33.2

.serverless/cloudformation-template-update-stack.json does contain a definition for PhotoTopic, but one is not created in the deployment of the main stack on my AWS account.

If I remove the serverless-aws-alias plugin, then I do get the PhotoTopic resource created in my AWS account.

What am I doing wrong? Does this plugin actually work?

Additional info: The issue appears to be around the use of Outputs, which I need to use from other stacks (Exports). If I remove the Outputs, then I do get my PhotoTopic created.

But I need to reference that Topic as an Exported value, how can this be done?

aleksdikanski commented 5 years ago

For the question regarding the Exported Value: I'm not a complete cloudformation expert, but I would suggest to Export your Output value. see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-exports.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html

brenoreis commented 5 years ago

Same issue here.

victorwhy commented 5 years ago

Running into the same issue here; the Cloudformation template is completely missing an SNS resource that we've defined snsInvokeHook. Our serverless.yml has it defined like so:

...
resources:
  Resources:
    snsInvokeHook:
      Type: AWS::SNS::Topic
      Properties:
        TopicName: ${self:service}-${self:provider.stage}-sns
    snsTopicPolicy:
      Type: AWS::SNS::TopicPolicy
      Properties:
        PolicyDocument:
          Version: '2012-10-17'
          Statement:
          - Sid: snsTopicPolicy
            Effect: Allow
            Principal:
              Service: events.amazonaws.com
            Action: sns:Publish
            Resource: "*"
        Topics:
          - Ref: snsInvokeHook
...

But when I run the deploy with the alias, i get this:

Serverless: Validating template...
Serverless: [AWS cloudformation 400 0.143s 0 retries] validateTemplate({ TemplateURL:
   'https://s3.amazonaws.com/night-owl-development-serverlessdeploymentbucket-1069pfbzcqsjl/serverless/night-owl/development/1566334599396-2019-08-20T20:56:39.396Z/compiled-cloudformation-template.json' })

  Error --------------------------------------------------

  The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [snsInvokeHook] in the Resources block of the template

and when i go to the compiled Cloudformation template compiled-cloudformation-template.json snsInvokeHook is no longer there. It compiles to

    "ApiGatewayUsagePlanKey1": {
      "Type": "AWS::ApiGateway::UsagePlanKey",
      "Properties": {
        "KeyId": {
          "Ref": "ApiGatewayApiKey1"
        },
        "KeyType": "API_KEY",
        "UsagePlanId": {
          "Ref": "ApiGatewayUsagePlan"
        }
      }
    },
    "snsTopicPolicy": {
      "Type": "AWS::SNS::TopicPolicy",
      "Properties": {
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "snsTopicPolicy",
              "Effect": "Allow",
              "Principal": {
                "Service": "events.amazonaws.com"
              },
              "Action": "sns:Publish",
              "Resource": "*"
            }
          ]
        },
        "Topics": [
          {
            "Ref": "snsInvokeHook"
          }
        ]
      }
    },

If i run the same thing WITHOUT serverless-aws-alias, the snsInvokeHook is clearly there in the Cloudformation template

"HookLambdaPermissionNightowldevelopmentsnsSNS": {
      "Type": "AWS::Lambda::Permission",
      "Properties": {
        "FunctionName": {
          "Fn::GetAtt": [
            "HookLambdaFunction",
            "Arn"
          ]
        },
        "Action": "lambda:InvokeFunction",
        "Principal": "sns.amazonaws.com",
        "SourceArn": {
          "Fn::Sub": "arn:aws:sns:us-east-1:${AWS::AccountId}:night-owl-development-sns"
        }
      }
    },
    "snsInvokeHook": {
      "Type": "AWS::SNS::Topic",
      "Properties": {
        "TopicName": "night-owl-development-sns"
      }
    },
    "snsTopicPolicy": {
      "Type": "AWS::SNS::TopicPolicy",
      "Properties": {
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "snsTopicPolicy",
              "Effect": "Allow",
              "Principal": {
                "Service": "events.amazonaws.com"
              },
              "Action": "sns:Publish",
              "Resource": "*"
            }
          ]
        },
        "Topics": [
          {
            "Ref": "snsInvokeHook"
          }
        ]
      }
    },

It looks like everyone else is running into the same thing here - is serverless-aws-alias just not compatible with any SNS functionality?