将 CreateEnvironmentEc2 与 CLI 配合使用 - AWS SDK 代码示例

AWS 文档 SDK 示例 GitHub 存储库中还有更多 AWS SDK 示例。

CreateEnvironmentEc2 与 CLI 配合使用

以下代码示例演示如何使用 CreateEnvironmentEc2

CLI
AWS CLI

创建 AWS Cloud9 EC2 开发环境

以下 create-environment-ec2 示例使用指定设置创建 AWS Cloud9 开发环境,启动 Amazon Elastic Compute Cloud(Amazon EC2)实例,然后将该实例连接到环境。

aws cloud9 create-environment-ec2 \ --name my-demo-env \ --description "My demonstration development environment." \ --instance-type t2.micro --image-id amazonlinux-2023-x86_64 \ --subnet-id subnet-1fab8aEX \ --automatic-stop-time-minutes 60 \ --owner-arn arn:aws:iam::123456789012:user/MyDemoUser

输出:

{ "environmentId": "8a34f51ce1e04a08882f1e811bd706EX" }

有关更多信息,请参阅《AWS Cloud9 用户指南》中的创建 EC2 环境

PowerShell
Tools for PowerShell V4

示例 1:此示例使用指定的设置创建 AWS Cloud9 开发环境,启动 Amazon Elastic Compute Cloud(Amazon EC2)实例,然后从该实例连接到环境。

New-C9EnvironmentEC2 -Name my-demo-env -AutomaticStopTimeMinutes 60 -Description "My demonstration development environment." -InstanceType t2.micro -OwnerArn arn:aws:iam::123456789012:user/MyDemoUser -SubnetId subnet-d43a46EX

输出

ffd88420d4824eeeaeaa8a04bfde8cEX
  • 有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V4)》中的 CreateEnvironmentEc2

Tools for PowerShell V5

示例 1:此示例使用指定的设置创建 AWS Cloud9 开发环境,启动 Amazon Elastic Compute Cloud(Amazon EC2)实例,然后从该实例连接到环境。

New-C9EnvironmentEC2 -Name my-demo-env -AutomaticStopTimeMinutes 60 -Description "My demonstration development environment." -InstanceType t2.micro -OwnerArn arn:aws:iam::123456789012:user/MyDemoUser -SubnetId subnet-d43a46EX

输出

ffd88420d4824eeeaeaa8a04bfde8cEX
  • 有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V5)》中的 CreateEnvironmentEc2