I'm following the AWS guide for deploying an HA Wordpress site to Elastic Beanstalk which includes using the eb-php-wordpress extension. The process requires editing a couple of configuration files with known resource IDs prior to deploying the application.
In particular, the instructions say to edit the efs-create.config file with a VPC ID, and Subnet IDs. The file, among other things, helps set the OptionSettings property of the AWS::ElasticBeanstalk::Environment resource. Thanks to danimal, I now know how to pull the VpcId into the file using Fn::GetAtt
:
option_settings:
aws:elasticbeanstalk:customoption:
EFSVolumeName: "EB-EFS-Volume"
VPCId: { "Fn::GetAtt" : [ "AWSEBSecurityGroup", "VpcId" ] }
## Subnet Options
SubnetA: "subnet-XXXXXXXX"
SubnetB: "subnet-XXXXXXXX"
SubnetC: "subnet-XXXXXXXX"
SubnetD: "subnet-XXXXXXXX"
Now my obstacle is getting those subnet IDs added. I tried applying the same, but slightly expanded, concept to the AWSEBV2LoadBalancer
resource to pull the Subnets array, but I got an error.
The code:
SubnetA: { "Fn::Select" : [ "0", { "Fn::GetAtt" : [ "AWSEBV2LoadBalancer", "Subnets" ] } ] }
SubnetB: { "Fn::Select" : [ "1", { "Fn::GetAtt" : [ "AWSEBV2LoadBalancer", "Subnets" ] } ] }
SubnetC: { "Fn::Select" : [ "2", { "Fn::GetAtt" : [ "AWSEBV2LoadBalancer", "Subnets" ] } ] }
SubnetD: { "Fn::Select" : [ "3", { "Fn::GetAtt" : [ "AWSEBV2LoadBalancer", "Subnets" ] } ] }
The error:
Service:AmazonCloudFormation, Message:Template error: resource AWSEBV2LoadBalancer does not support attribute type Subnets in Fn::GetAtt
I found this odd since the generated template shows Subnets
under that resouce :
"AWSEBV2LoadBalancer": {
"Properties": {
"SecurityGroups": [
{
"Ref": "AWSEBLoadBalancerSecurityGroup"
}
],
"Subnets": [
"subnet-0ec0699f08ff45e6e",
"subnet-0a4fec611d42b062f",
"subnet-09a4c28b8f330c0c3",
"subnet-0ea8d69e46ce87afc"
]
},
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer"
},
I also tried assigning the array using Subnets: { "Fn::GetAtt" : [ "AWSEBV2LoadBalancer", "Subnets" ]
and then using Fn::Select
and Ref
on that: SubnetA: { "Fn::Select" : [ "0", [ "Ref" : "Subnets" ] ] }
but that created its own error:
Service:AmazonCloudFormation, Message:Template format error: Unresolved resource dependencies [Subnets] in the Resources block of the template
How do I extract that array and assign each element to a different resource?
Per the docs (per danimal), this is not possible. Leaves me wondering how others have done it as I can't imagine I'm the first to try.