Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Elastic Beanstalk - Environment must have instance profile associated with it

I am working on a project that will programmatically create environments in AWS elastic beanstalk. I am using the AWS SDK for PHP Version 3.

My script creates the environment. From the AWS console, the environment is displayed in gray and says that it is terminated. Viewing the events shows that an error of "Environment must have instance profile associated with it".

Link to events error screenshot

I have tried using the access key and secret of two different users. One user has AmazonEC2FullAccess, IAMFullAccess, and AWSElasticBeanstalkFullAccess permissions. The other user has AWSAdmin permissions. Both users can create environments from the AWS console.

I do not know how to associate an instance profile with an environment from the SDK. I do not see an option to do it with the createEnvironment function: createEnvironment syntax I also do not see a way to do it when creating an instance of the ElasticBeanstalkClient object.

My code is below. Thanks.

<?php
    require 'vendor/autoload.php';
    use Aws\ElasticBeanstalk\ElasticBeanstalkClient;
    use Aws\Credentials\Credentials;

    $key = '***key***';
    $secret = '***secret***';

    $credentials = new Credentials($key, $secret);
    $ebClient = new ElasticBeanstalkClient([
        'region'  => 'us-east-2',
        'version' => '2010-12-01',
        'credentials' => $credentials
    ]);

    $ebEnv = $ebClient->createEnvironment([
        'ApplicationName' => 'app-from-sdk',
        'EnvironmentName' => 'env-from-sdk-1',
        'CNAMEPrefix'     => 'sdk-test1',
        'Description'     => 'Test environment created from SDK.',
        //'TemplateName'    => 'PHP 7.1 version 2.7.1',
        'SolutionStackName' => '64bit Amazon Linux 2018.03 v2.7.1 running PHP 
7.1',
        'VersionLabel'    => 'Sample Application'
    ]);
    echo '<pre>';
    var_dump($ebEnv);
    echo '</pre>';
like image 544
Jessie Edmisten Avatar asked Jul 31 '18 18:07

Jessie Edmisten


People also ask

What is the use of instance profile in AWS?

An instance profile is a container for an IAM role that you can use to pass role information to an EC2 instance when the instance starts.

What are the two environments available in Elastic Beanstalk?

In AWS Elastic Beanstalk, you can create a load-balanced, scalable environment or a single-instance environment.

What is AWS Elastic Beanstalk environments?

An AWS Elastic Beanstalk environment is a collection of AWS resources running an application version. You can deploy multiple environments when you need to run multiple versions of an application. For example, you might have development, integration, and production environments.

How do you access the Elastic Beanstalk environment?

Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Environments, and then choose the name of your environment from the list. If you have many environments, use the search bar to filter the environment list.


1 Answers

You are missing the following attributes in your createEnvironment attribute map/hash you pass:

OptionSettings.member.1.Namespace = aws:autoscaling:launchconfiguration
OptionSettings.member.1.OptionName = IamInstanceProfile
OptionSettings.member.1.Value = aws-elasticbeanstalk-ec2-role

Source: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-create-api.html

like image 111
srikanth Nutigattu Avatar answered Nov 16 '22 02:11

srikanth Nutigattu