I am trying to automate the deployment and invoke lambda function using ansible playbook.To get the arn of the lambda function,I wrote a json query. But here, I need only arn(arn:aws:lambda:us-west-2:1234567890:function:dev-Hello-World) but the Ansible script generates arn with version number (arn:aws:lambda:us-west-2:1234567890:function:dev-Hello-World:50). I used set_fact and json query to get the arn. But, I want to remove the version number and colon at the end.
I tried to use regex and replace to remove the strings. I am new to JSON and programming.
- name: Get the Hello-world arn
set_fact:
populate_arn: "{{ Hello-World | json_query('results[0].configuration.function_arn')}}"
- debug:
var: populate_arn
Expected result:arn:aws:lambda:us-west-2:1234567890:function:dev-Hello-World
Actual result: arn:aws:lambda:us-west-2:1234567890:function:dev-Hello-World:50
Foremost, as one can see from the Lambda API documentation, that ARN is the correct, stable, identifier for the function. If you remove the :50 qualifier, you will get whatever is the :$LATEST which can absolutely produce erroneous results
That said, the output from json_query is just a string, so you can continue your jinja2 pipeline with (as you mentioned) regex_replace to strip the qualifier:
- set_fact:
populate_arn: "{{ Hello-World | json_query('results[0].configuration.function_arn') | regex_replace(':[^:]+$', '') }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With