I'm trying to put my lambdas in the appropriate VPC given the environment. How can that be achieved given I'm building the VPCs in a separate nested stack given the environment?
Using Github actions and sam deploy if that matters.
Parameters:
environment:
Type: String
devLambdaSubnetIds:
Type: String
Default: !Join [',', subnet-[devVpcA], subnet-[devVpcB]]
prodLambdaSubnetIds:
Type: String
Default: !Join [',', subnet-[prodVpcA], subnet-[prodVpcB]]
...
Resources:
HealthCheckFunction:
Type: AWS::Serverless::Function
Properties:
...
VpcConfig:
Ipv6AllowedForDualStack: false
SecurityGroupIds:
- !Ref genericSecurityGroup
SubnetIds: HERE THIS NEEDS TO BE !Ref devLambdaSubnetIds or !Ref prodLambdaSubnetIds depending on the environment (which is either 'dev' or 'prod')
You could use a mapping and keep config for each env in the mapping.
In the example below the subnet ids would need to be changed for real subnet ids.
You could alternately store the subnet ids in param store at paths like;
Then, reference them in your template like this;
You could use conditions as well.
Then add in the condition to the resource. You would need two distinct resources, one for dev and one for prod then, though.