I read the documentation for AWS Cloudformation Resources and there’s no mention of how to reference the resources elsewhere in my serverless.yml. It does link to the documentation for using variables from other “stacks”, but what about the current stack?
I figured this out on my own through trial and error, but I want to know why it’s not in the documentation.
You can reference the resources using the !Ref
“function”, like so:
provider:
vpc:
subnetIds:
- !Ref privateSubnetA
- !Ref privateSubnetB
resources:
Resources:
privateSubnetA:
Type: AWS::EC2::Subnet
Properties:
VpcId: something
AvailabilityZone: something
CidrBlock: something
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: "something"
privateSubnetB:
Type: AWS::EC2::Subnet
Properties:
VpcId: something
AvailabilityZone: something
CidrBlock: something
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: "something"