Matching hosts in AWS (or any dynamic inventory?)

Hello!
I would like to match hosts in AWS with something like (passing env as an extravar):
hosts: tag_Function_www:&ec2_tag_Environment=env

I’m currently using this which works:
hosts: “tag_Function_www:&tag_Environment_{{ env|default(‘test’) }}”

but wondering if there’s a better way. Any thoughts would be appreciated

Thanks!
Gu