D'autres AWS SDK exemples sont disponibles dans le GitHub dépôt AWS Doc SDK Examples
Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
À utiliser UpdateApplication
avec un AWS SDK ou CLI
Les exemples de code suivants montrent comment utiliserUpdateApplication
.
- CLI
-
- AWS CLI
-
Pour modifier la description d'une application
La commande suivante met à jour la description d'une application nommée
my-app
:aws elasticbeanstalk update-application --application-name
my-app
--description"my Elastic Beanstalk application"
Sortie :
{ "Application": { "ApplicationName": "my-app", "Description": "my Elastic Beanstalk application", "Versions": [ "2fba-stage-150819_234450", "bf07-stage-150820_214945", "93f8", "fd7c-stage-150820_000431", "22a0-stage-150819_185942" ], "DateCreated": "2015-08-13T19:15:50.449Z", "ConfigurationTemplates": [], "DateUpdated": "2015-08-20T22:34:56.195Z" } }
-
Pour API plus de détails, voir UpdateApplication
la section Référence des AWS CLI commandes.
-
- Ruby
-
- SDKpour Ruby
-
Note
Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS
. # Manages deployment of Rails applications to AWS Elastic Beanstalk class RailsAppDeployer def initialize(eb_client, s3_client, app_name, logger: Logger.new($stdout)) @eb_client = eb_client @s3_client = s3_client @app_name = app_name @logger = logger end # Deploys the latest application version to Elastic Beanstalk def deploy create_storage_location zip_file_name = create_zip_file upload_zip_to_s3(zip_file_name) create_and_deploy_new_application_version(zip_file_name) end private # Creates a new S3 storage location for the application def create_storage_location resp = @eb_client.create_storage_location @logger.info("Created storage location in bucket #{resp.s3_bucket}") rescue Aws::Errors::ServiceError => e @logger.error("Failed to create storage location: #{e.message}") end # Creates a ZIP file of the application using git def create_zip_file zip_file_basename = SecureRandom.urlsafe_base64 zip_file_name = "#{zip_file_basename}.zip" `git archive --format=zip -o #{zip_file_name} HEAD` zip_file_name end # Uploads the ZIP file to the S3 bucket def upload_zip_to_s3(zip_file_name) zip_contents = File.read(zip_file_name) key = "#{@app_name}/#{zip_file_name}" @s3_client.put_object(body: zip_contents, bucket: fetch_bucket_name, key: key) rescue Aws::Errors::ServiceError => e @logger.error("Failed to upload ZIP file to S3: #{e.message}") end # Fetches the S3 bucket name from Elastic Beanstalk application versions def fetch_bucket_name app_versions = @eb_client.describe_application_versions(application_name: @app_name) av = app_versions.application_versions.first av.source_bundle.s3_bucket rescue Aws::Errors::ServiceError => e @logger.error("Failed to fetch bucket name: #{e.message}") raise end # Creates a new application version and deploys it def create_and_deploy_new_application_version(zip_file_name) version_label = File.basename(zip_file_name, '.zip') @eb_client.create_application_version( process: false, application_name: @app_name, version_label: version_label, source_bundle: { s3_bucket: fetch_bucket_name, s3_key: "#{@app_name}/#{zip_file_name}" }, description: "Updated #{Time.now.strftime('%d/%m/%Y')}" ) update_environment(version_label) rescue Aws::Errors::ServiceError => e @logger.error("Failed to create or deploy application version: #{e.message}") end # Updates the environment to the new application version def update_environment(version_label) env_name = fetch_environment_name @eb_client.update_environment( environment_name: env_name, version_label: version_label ) rescue Aws::Errors::ServiceError => e @logger.error("Failed to update environment: #{e.message}") end # Fetches the environment name of the application def fetch_environment_name envs = @eb_client.describe_environments(application_name: @app_name) envs.environments.first.environment_name rescue Aws::Errors::ServiceError => e @logger.error("Failed to fetch environment name: #{e.message}") raise end end
-
Pour API plus de détails, voir UpdateApplicationla section AWS SDK for Ruby APIRéférence.
-