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

坚强是说给别人听的谎言 提交于 2020-06-27 11:59:10

问题


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".

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>';

回答1:


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



来源:https://stackoverflow.com/questions/51619828/aws-elastic-beanstalk-environment-must-have-instance-profile-associated-with-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!