I'm trying to include an optional `AWS::EC2::SecurityGroup::Id` parameter in my CloudFormation template by setting it to `Default: ''`, but I keep running into deployment errors. I can use `Type: String` as a workaround, but it feels like a design flaw that allows basic types to be optional while blocking AWS-specific types. Is there a reason for this? Also, all parameter values seem to be treated as strings, with the empty string standing in for omitted parameters instead of `null`. I'm using conditions with the parameter successfully when it's a `String`, but I get a validation error if it's set as `AWS::EC2::SecurityGroup::Id`. Does anyone have insights on this?
2 Answers
I've been stuck in the same boat. Never managed to use those specific types without falling back to `String` either. It definitely seems like a limitation on AWS's part. It’d be great if they clarified this in their documentation too!
From what I've seen, CloudFormation really doesn't allow optional AWS-specific parameter types well. Using `String` seems to be the only way to avoid errors, even if it feels like a hack. I wish they'd allow more flexibility for the types, especially since we often need to conditionally pass IDs. It'd be nice to hear if someone has figured out a better approach!

Yeah, I agree. It's frustrating how restrictive this can be. AWS really needs to look into allowing a clearer way to handle these specific types.