mapbox / magic-cfn-resources

Build Lambda-backed custom CloudFormation resources ✨
4 stars 5 forks source link

Issue with custom resources #2

Closed rclark closed 7 years ago

rclark commented 7 years ago

https://github.com/mapbox/magic-cfn-resources/blob/dabccbb2068118687bb1310143dc139152e3da29/lib/build.js#L349

This gets rejected by CloudFormation: Name is not valid in this part of a resource. I think that the Logical Name that gets provided by the caller needs to be used as the Resource Key for each of the resources that .build() is going to provide.

For example, the SpotFleet resource is gonna give you a

Imagine I want to build a stack with 2 spot fleets. In my final template I can't have a Resources block that looks like this:

{
  Resources: {
    SpotFleetFunction: { // for my first fleet
      Type: 'AWS::Lambda::Function'
      Properties: { ... } 
    },
    ... other resources ...
    SpotFleetFunction: { // for my second fleet
      Type: 'AWS::Lambda::Function'
      Properties: { ... } 
    }
  }
}

They have to have two different "logical names":

{
  Resources: {
    MyFirstSpotFleetFunction: { // for my first fleet
      Type: 'AWS::Lambda::Function'
      Properties: { ... } 
    },
    ... other resources ...
    MySecondSpotFleetFunction: { // for my second fleet
      Type: 'AWS::Lambda::Function'
      Properties: { ... } 
    }
  }
}

Having the caller provide a LogicalName option is the right step to take in order to make this happen -- you just need to apply to the keys for each resource that .build() is creating.

cc @kellyoung

kellyoung commented 7 years ago

Thanks for looking this over! Going to start a PR.

kellyoung commented 7 years ago

👋 @rclark

Could I get your stamp of approval/disapproval whenever you get the chance? https://github.com/mapbox/magic-cfn-resources/pull/3 https://github.com/mapbox/magic-cfn-resources/blob/logicalname/lib/build.js#L323-L326