serverless-aws-alias icon indicating copy to clipboard operation
serverless-aws-alias copied to clipboard

AWS Conditions is not defined / missing in alias stack

Open arabold opened this issue 6 years ago • 1 comments

I'm trying to use AWS Conditions in order to create conditional Resources.

Conditions generally work like this in your serverless.yaml:

...
resources:
  Conditions:
    IsProdCondition:
      Fn::Equals: [ '${self:custom.stage}', 'prod' ]

  Resources:
    MyResource:
      Type: AWS::S3::Bucket
      Condition: IsProdCondition
      ...

Unfortunately that doesn't work with the Alias plugin 😢

While the Conditions section properly appears in the cloudformation-template-update-stack.json stack, it's missing in the cloudformation-template-update-alias-stack.json one. This causes an error during deployment:

Template format error: Condition IsProdCondition is not defined.

The simplest solution should be to copy the Conditions section in both stack JSONs. Then it's accessible in both cases and even if might not always be necessary, it doesn't hurt to have a superfluous condition defined either.

arabold avatar Jun 14 '18 23:06 arabold

Conditions should be defined outside of resources between Parameters and Resources

tanyingwang avatar Mar 14 '23 16:03 tanyingwang