### Instruction:
Create a Python script that automates the deployment of a web application to an AWS EC2 instance using Boto3. The script should launch a new instance, configure security groups, install necessary software (e.g., Node.js, Nginx), deploy the application code from a Git repository, and start the application.

### Response:

To create a Python script that automates the deployment of a web application to an AWS EC2 instance using Boto3, follow these steps:

1. Install Boto3 by running `pip install boto3`
2. Configure your AWS credentials by following [these instructions](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration)
3. Create a new file called `deploy.py` and add the following code:

```python
import boto3
import time

ec2 = boto3.resource('ec2')


def create_instance():
    print("Creating instance...")
    instance = ec2.create_instances(
        ImageId='ami-0c94855ba95b798c7',  # Amazon Linux 2 AMI ID (change if needed)
        MinCount=1,
        MaxCount=1,
        InstanceType='t2.micro',
        KeyName='your-key-pair-name'  # Replace with your key pair name
    )[0]

    instance.wait_until_running()
    instance.reload()

    return instance


def configure_security_group(instance):
    print("Configuring security group...")
    security_group = ec2.create_security_group(
        GroupName='webapp-sg',
        Description='Security group for web application'
    )

    security_group.authorize_ingress(
        IpProtocol="tcp",
        FromPort=22,
        ToPort=22,
        CidrIp="0.0.0.0/0"
    )
    security_group.authorize_ingress(
        IpProtocol="tcp",
        FromPort=80,
        ToPort=80,
        CidrIp="0.0.0.0/0"
    )

    instance.modify_attribute(Groups=[security_group.id])


def deploy_application(instance):
    print("Deploying application...")

    user_data_script = """#!/bin/bash
    yum update -y
    yum install git -y
    curl --silent --location https://rpm.nodesource.com/setup_14.x | bash -
    yum install nodejs -y
    yum install nginx -y

    systemctl start nginx
    systemctl enable nginx

    git clone https://github.com/your-username/your-repo.git /var/www/webapp
    cd /var/www/webapp
    npm install
    npm run build

    cat > /etc/nginx/conf.d/webapp.conf <<EOL
    server {
        listen 80;
        server_name _;

        location / {
            root /var/www/webapp/dist;
            try_files $uri $uri/ /index.html;
        }
    }
    EOL

    systemctl restart nginx
    """

    instance.stop()
    instance.wait_until_stopped()

    instance.modify_attribute(
        UserData=user_data_script
    )

    instance.start()
    instance.wait_until_running()


def main():
    instance = create_instance()
    configure_security_group(instance)
    deploy_application(instance)

    print(f"Application deployed to: http://{instance.public_dns_name}")


if __name__ == "__main__":
    main()
```

4. Replace `your-key-pair-name` with the name of your EC2 key pair.
5. Replace `https://github.com/your-username/your-repo.git` with the URL of your Git repository containing the web application code.
6. Run the script by executing `python deploy.py`. This will launch a new EC2 instance, configure security groups, install necessary software, and deploy the application.

Note that this script assumes you are using an Amazon Linux 2 AMI and have Node.js and Nginx installed on your instance. Modify the user data script as needed for your specific application requirements.