Brian
Brian

Reputation: 13593

How to specify a custom amazon machine image(AMI) ID when creating elastic beanstalk environments with CLI?

I've learned how to use custom AMI ID with Elastic Beanstalk Console from this tutorial.

How can I do the same thing with aws elasticbeanstalk or eb commands?

I couldn't find how to do it from AWS CLI Command Reference.

And I feel like that the PlatformArn value in the saved configuration file must be changed if I want to use a custom AMI ID.

Any knows how to specify custom AMI ID with command lines?

Upvotes: 1

Views: 1119

Answers (1)

John Hanley
John Hanley

Reputation: 81434

In order to specify the AMI ID you will need to manage more of your Beanstalk environment. While you are getting started with these features, I recommend that you start using an existing AMI that works with Beanstalk (pick one that you have already tested).

The key is that the AMI ID is part of the launch configuration.

CLI:

aws elasticbeanstalk create-environment --region us-west-2 --application-name my-app --environment-name my-env --version-label v1 --solution-stack-name "64bit Windows Server 2016 v1.2.0 running IIS 10.0" --option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=ImageId,Value="ami-xxxxxxx"

SDK:

You can specify the AMI ID via the OptionSettings in the createEnvironment() call.

Sample code:

var var params = {
  ApplicationName: "my-app", 
  CNAMEPrefix: "my-app", 
  EnvironmentName: "my-env", 
  SolutionStackName: "64bit Windows Server 2016 v1.2.0 running IIS 10.0", 
  VersionLabel: "v1",
  OptionSettings: [
    {
      Namespace: 'aws:autoscaling:launchconfiguration',
      OptionName: 'ImageId',
      Value: 'ami-xxxxxxx'
    },
  ],
 };
 elasticbeanstalk.createEnvironment(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
 });

This article discusses the above methods in detail:

Using a custom AMI with Elastic Beanstalk

Upvotes: 1

Related Questions