I am using the AWS SDK on php to get instance information for remote desktop clients. I've included an example of one member of the array I'm retrieving. I'm already filtering by one of the tags offered in this array to only receive items of the group "ABC". Once this is filtered, I'm wanting to retrieve the value of the other tag known as "clientId" for each member of the array. Because the index is inconsistent, I cannot simply select the item by saying $results['Instances'][0]['Tags'][0]['Value]. Sometimes it is a different number (like $results['Instances'][0]['Tags'][1]['Value]). I would like to select it according to its sibling (Key => clientId) but I can't find a way to do that.
Thank you for any help you may provide.
This an example of one array member returned by 'describeInstances' AWS SDK:
[0] => Array
(
[Groups] => Array
(
)
[Instances] => Array
(
[0] => Array
(
[AmiLaunchIndex] => 0
[ImageId] => ami-11111111111111111
[InstanceId] => i-11111111111111111
[InstanceType] => t3.large
[KeyName] => awskeypair_PUBLIC
[LaunchTime] => Aws\Api\DateTimeResult Object
(
[date] => 2019-06-22 04:08:37.000000
[timezone_type] => 2
[timezone] => Z
)
[Monitoring] => Array
(
[State] => disabled
)
[Placement] => Array
(
[AvailabilityZone] => us-west-1a
[GroupName] =>
[Tenancy] => default
)
[Platform] => windows
[PrivateDnsName] => ip-111-11-11-111.us-west-1.compute.internal
[PrivateIpAddress] => 111.11.11.1111 [ProductCodes] => Array
(
)
[PublicDnsName] => ec2-11-11-11-11.us-west-1.compute.amazonaws.com
[PublicIpAddress] => 11.11.11.11
[State] => Array
(
[Code] => 16
[Name] => running
)
[StateTransitionReason] =>
[SubnetId] => subnet-1111c1f1
[VpcId] => vpc-e11fb111
[Architecture] => x86_64
[BlockDeviceMappings] => Array
(
[0] => Array
(
[DeviceName] => /dev/sda1
[Ebs] => Array
(
[AttachTime] => Aws\Api\DateTimeResult Object
(
[date] => 2019-05-10 14:55:20.000000
[timezone_type] => 2
[timezone] => Z
)
[DeleteOnTermination] => 1
[Status] => attached
[VolumeId] => vol-11111111111111111
)
)
)
[ClientToken] =>
[EbsOptimized] => 1
[EnaSupport] => 1
[Hypervisor] => xen
[NetworkInterfaces] => Array
(
[0] => Array
(
[Association] => Array
(
[IpOwnerId] => amazon
[PublicDnsName] => ec2-11-11-11-11.us-west-1.compute.amazonaws.com
[PublicIp] => 11.11.11.11
)
[Attachment] => Array
(
[AttachTime] => Aws\Api\DateTimeResult Object
(
[date] => 2019-05-10 14:55:19.000000
[timezone_type] => 2
[timezone] => Z
)
[AttachmentId] => eni-attach-1111111111111111
[DeleteOnTermination] => 1
[DeviceIndex] => 0
[Status] => attached
)
[Description] =>
[Groups] => Array
(
[0] => Array
(
[GroupName] => launch-wizard-20
[GroupId] => sg-11111111111111111
)
)
[Ipv6Addresses] => Array
(
)
[MacAddress] => 02:5e:b0:33:b0:6e
[NetworkInterfaceId] => eni-023ccaf7dd1ade14c
[OwnerId] => 111111111111
[PrivateDnsName] => ip-111-11-11-111.us-west-1.compute.internal
[PrivateIpAddress] => 111.11.11.111
[PrivateIpAddresses] => Array
(
[0] => Array
(
[Association] => Array
(
[IpOwnerId] => amazon
[PublicDnsName] => ec2-11-11-11-11.us-west-1.compute.amazonaws.com
[PublicIp] => 11.11.11.11
)
[Primary] => 1
[PrivateDnsName] => ip-111-11-11-111.us-west-1.compute.internal
[PrivateIpAddress] => 111.11.11.111
)
)
[SourceDestCheck] => 1
[Status] => in-use
[SubnetId] => subnet-11111111
[VpcId] => vpc-e08fb484
[InterfaceType] => interface
)
)
[RootDeviceName] => /dev/sda1
[RootDeviceType] => ebs
[SecurityGroups] => Array
(
[0] => Array
(
[GroupName] => launch-wizard-20
[GroupId] => sg-1c1111111c111d17b
)
)
[SourceDestCheck] => 1
[Tags] => Array
(
[0] => Array
(
[Key] => clientId
[Value] => 1234
)
[1] => Array
(
[Key] => Group
[Value] => ABC
)
[2] => Array
(
[Key] => Name
[Value] => ABC - This company's name
)
)
[VirtualizationType] => hvm
[CpuOptions] => Array
(
[CoreCount] => 1
[ThreadsPerCore] => 2
)
[CapacityReservationSpecification] => Array
(
[CapacityReservationPreference] => open
)
[HibernationOptions] => Array
(
[Configured] =>
)
)
)
[OwnerId] => 621273892911
[ReservationId] => r-1111111111111111
)