简体   繁体   English

如何通过设置密钥对名称的 boto3 创建 elasticbeanstalk 环境

[英]How to create an elasticbeanstalk environment through boto3 setting a keypair name

If you uses the AWS console or even the command line, you won't get any issue in setting a default keypair to your Elasticbeanstalk environment.如果您使用 AWS 控制台甚至命令行,则在为 Elasticbeanstalk 环境设置默认密钥对时不会遇到任何问题。

But you do if using boto3.但是如果使用 boto3,你会这样做。

Surprisingly, there's no any single mention about setting a keypair in the official boto3 documentation for elasticbeanstalk: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticbeanstalk.html .令人惊讶的是,在 elasticbeanstalk 的官方 boto3 文档中没有任何关于设置密钥对的提及: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticbeanstalk.html

Tried also to create a zip file containing the most basic files to make a simple website works.还尝试创建一个包含最基本文件的 zip 文件,以使简单的网站正常运行。 And supposedly, I can set a keypair name in the .elasticbeanstalk/config.yml ". I did in this way:据推测,我可以在.elasticbeanstalk/config.yml中设置一个密钥对名称。我是这样做的:

branch-defaults:
  default:
    environment: app10-env
    group_suffix: null
global:
  application_name: app10
  branch: null
  default_ec2_keyname: main4
  default_platform: PHP 7.4 running on 64bit Amazon Linux 2
  default_region: us-east-1
  include_git_submodules: true
  instance_profile: null
  platform_name: null
  platform_version: null
  profile: null
  repository: null
  sc: null
  workspace_type: null

Yes, the " main4 " exists in my AWS account.是的,我的 AWS 账户中存在“ main4 ”。 But creating an environment to my application with a zip containing it, it seems that it have no effect at all.但是用包含它的 zip 为我的应用程序创建一个环境,似乎它根本没有效果。 After my environment has sucessfully deployed, I can check afterwards through console and see that have no keypair setted to environment.在我的环境成功部署后,我可以通过控制台检查并查看没有为环境设置密钥对。 I need to go to a further step on console to set the keypair and await a new environment deployiment to perform the update.我需要 go 在控制台上进一步设置密钥对并等待新的环境部署来执行更新。

Is there a real issue with the boto3 elasticbeanstalk when dealing with environment keypairs or I am doing something wrong?在处理环境密钥对时,boto3 elasticbeanstalk 是否存在真正的问题,或者我做错了什么?

I would set the OptionSettings when calling create_environment or include the keyname in the .ebextensions .我会在调用create_environment时设置 OptionSettings 或在.ebextensions中包含键名。 Boto3 is not reading the EB CLI default config you are using i guess.我猜 Boto3 没有读取您正在使用的 EB CLI 默认配置。

Refs参考文献

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticbeanstalk.html#ElasticBeanstalk.Client.create_environment https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticbeanstalk.html#ElasticBeanstalk.Client.create_environment

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-configuration-methods-before.html https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-configuration-methods-before.html

Option to set选项设置

  • Namespace: aws:autoscaling:launchconfiguration命名空间:aws:autoscaling:launchconfiguration
  • Option Names: IamInstanceProfile, EC2KeyName, InstanceType选项名称:IamInstanceProfile、EC2KeyName、InstanceType

The response of @f7o is not accurate, but helped to solve the problem. @f7o 的回复不准确,但帮助解决了问题。

There's no option for setting an keypair using " create_environment " command from boto3 client.没有使用来自 boto3 客户端的“ create_environment ”命令设置密钥对的选项。 Tried to use a " EC2KeyName ", but it returned an exception of invalid value.尝试使用“ EC2KeyName ”,但它返回了无效值的异常。

But using the " ebextensions " do the work.但是使用“ ebextensions ”来完成这项工作。 If someone else are interested in do the same task that I am, so everything that is needed to do is create a folder called " .ebextensions " with a file called " customkey.config " (the file name can be anything, but must be suffixed with .config ), and with the following content:如果其他人有兴趣做与我相同的任务,那么需要做的就是创建一个名为“ .ebextensions ”的文件夹,其中包含一个名为“ customkey.config ”的文件(文件名可以是任何名称,但必须是后缀为.config ),并包含以下内容:

option_settings:
  - namespace: aws:autoscaling:launchconfiguration
    option_name: EC2KeyName
    value: <your_keypair_name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM