Hi@akhtar,
To configure your inventory dynamically you need to use python scripts. You can download the script from the below-given link.
https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py
After that, you can do SSH in your EC2 instance and can configure something. You can take help from the below playbook.
- hosts: all
  remote_user: ec2-user
  become: yes
  tasks:
  - name: Install httpd
    package:
      name: httpd
      state: present