flaskdeploymentamazon-elastic-beanstalk

The instance profile associated with the environment does not exist


I used CodePipeline to integrate my GitHub Repo and encountered an error when I tried to deploy my Flask application using AWS Elastic Beanstalk.

I tried to find the error and I got to know that my environment didn't even launch. enter image description here


Solution

  • The issue arises due to the security policies of AWS, which prevents Elastic Beanstalk from creating it's own instance profile. Now, an instance profile is required for an environment because it provides the necessary permissions and access rights to the EC2 instances that run your application.

    Steps to manually create an instance profile:

    1. search for "IAM"
    2. Users>Add users>username>set permissions
    3. select Attach policies directly and add these 4 permissions (AdministratorAccess, AWSElasticBeanstalkMulticontainerDocker, AWSElasticBeanstalkWebTier, AWSElasticBeanstalkWorkerTier)

    [create a Role]

    1. Roles>create role>{entity type: AWS service, use case: EC2>permissions:same as above}

    [link Role to the User using the user ARN we just created]

    1. Select Role>Trust relationships>Edit trust policy>Add a principal - {principal type: IAM Roles, ARN: user arn}>Update Policy

    [Create a new environment]

    1. Service access - (use an existing service role - {existing service role: Role_created, EC2 instance profile: Role_created})

    [We have successfully launched an environment]