awscdkcloud9alpha

package module
v2.251.0-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

README

AWS Cloud9 Construct Library

---

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


This module is part of the AWS Cloud Development Kit project.

AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a browser. It includes a code editor, debugger, and terminal. Cloud9 comes prepackaged with essential tools for popular programming languages, including JavaScript, Python, PHP, and more, so you don’t need to install files or configure your development machine to start new projects. Since your Cloud9 IDE is cloud-based, you can work on your projects from your office, home, or anywhere using an internet-connected machine. Cloud9 also provides a seamless experience for developing serverless applications enabling you to easily define resources, debug, and switch between local and remote execution of serverless applications. With Cloud9, you can quickly share your development environment with your team, enabling you to pair program and track each other's inputs in real time.

Creating EC2 Environment

EC2 Environments are defined with Ec2Environment. To create an EC2 environment in the private subnet, specify subnetSelection with private subnetType.

// create a cloud9 ec2 environment in a new VPC
vpc := ec2.NewVpc(this, jsii.String("VPC"), &VpcProps{
	MaxAzs: jsii.Number(3),
})
cloud9.NewEc2Environment(this, jsii.String("Cloud9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
})

// or create the cloud9 environment in the default VPC with specific instanceType
defaultVpc := ec2.Vpc_FromLookup(this, jsii.String("DefaultVPC"), &VpcLookupOptions{
	IsDefault: jsii.Boolean(true),
})
cloud9.NewEc2Environment(this, jsii.String("Cloud9Env2"), &Ec2EnvironmentProps{
	Vpc: defaultVpc,
	InstanceType: ec2.NewInstanceType(jsii.String("t3.large")),
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
})

// or specify in a different subnetSelection
c9env := cloud9.NewEc2Environment(this, jsii.String("Cloud9Env3"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	SubnetSelection: &SubnetSelection{
		SubnetType: ec2.SubnetType_PRIVATE_WITH_EGRESS,
	},
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
})

// print the Cloud9 IDE URL in the output
// print the Cloud9 IDE URL in the output
awscdk.NewCfnOutput(this, jsii.String("URL"), &CfnOutputProps{
	Value: c9env.IdeUrl,
})

Specifying EC2 AMI

Use imageId to specify the EC2 AMI image to be used:

defaultVpc := ec2.Vpc_FromLookup(this, jsii.String("DefaultVPC"), &VpcLookupOptions{
	IsDefault: jsii.Boolean(true),
})
cloud9.NewEc2Environment(this, jsii.String("Cloud9Env2"), &Ec2EnvironmentProps{
	Vpc: defaultVpc,
	InstanceType: ec2.NewInstanceType(jsii.String("t3.large")),
	ImageId: cloud9.ImageId_UBUNTU_18_04,
})

Cloning Repositories

Use clonedRepositories to clone one or multiple AWS Codecommit repositories into the environment:

import "github.com/aws/aws-cdk-go/awscdk"

// create a new Cloud9 environment and clone the two repositories
var vpc Vpc


// create a codecommit repository to clone into the cloud9 environment
repoNew := codecommit.NewRepository(this, jsii.String("RepoNew"), &RepositoryProps{
	RepositoryName: jsii.String("new-repo"),
})

// import an existing codecommit repository to clone into the cloud9 environment
repoExisting := codecommit.Repository_FromRepositoryName(this, jsii.String("RepoExisting"), jsii.String("existing-repo"))
cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ClonedRepositories: []CloneRepository{
		cloud9.CloneRepository_FromCodeCommit(repoNew, jsii.String("/src/new-repo")),
		cloud9.CloneRepository_*FromCodeCommit(repoExisting, jsii.String("/src/existing-repo")),
	},
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
})

Specifying Owners

Every Cloud9 Environment has an owner. An owner has full control over the environment, and can invite additional members to the environment for collaboration purposes. For more information, see Working with shared environments in AWS Cloud9).

By default, the owner will be the identity that creates the Environment, which is most likely your CloudFormation Execution Role when the Environment is created using CloudFormation. Provider a value for the owner property to assign a different owner, either a specific IAM User or the AWS Account Root User.

Owner is an IAM entity that owns a Cloud9 environment. Owner has their own access permissions, and resources. You can specify an Ownerin an EC2 environment which could be of the following types:

  1. Account Root
  2. IAM User
  3. IAM Federated User
  4. IAM Assumed Role

The ARN of the owner must satisfy the following regular expression: ^arn:(aws|aws-cn|aws-us-gov|aws-iso|aws-iso-b):(iam|sts)::\d+:(root|(user\/[\w+=/:,.@-]{1,64}|federated-user\/[\w+=/:,.@-]{2,32}|assumed-role\/[\w+=:,.@-]{1,64}\/[\w+=,.@-]{1,64}))$

Note: Using the account root user is not recommended, see environment sharing best practices.

To specify the AWS Account Root User as the environment owner, use Owner.accountRoot()

var vpc Vpc

cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
	Owner: cloud9.Owner_AccountRoot(jsii.String("111111111")),
})

To specify a specific IAM User as the environment owner, use Owner.user(). The user should have the AWSCloud9Administrator managed policy

The user should have the AWSCloud9User (preferred) or AWSCloud9Administrator managed policy attached.

import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


user := iam.NewUser(this, jsii.String("user"))
user.AddManagedPolicy(iam.ManagedPolicy_FromAwsManagedPolicyName(jsii.String("AWSCloud9Administrator")))
cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,

	Owner: cloud9.Owner_User(user),
})

To specify a specific IAM Federated User as the environment owner, use Owner.federatedUser(accountId, userName).

The user should have the AWSCloud9User (preferred) or AWSCloud9Administrator managed policy attached.

import iam "github.com/aws/aws-cdk-go/awscdk"

var vpc Vpc

cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
	Owner: cloud9.Owner_FederatedUser(awscdk.*stack_Of(this).Account, jsii.String("Admin/johndoe")),
})

To specify an IAM Assumed Role as the environment owner, use Owner.assumedRole(accountId: string, roleName: string).

The role should have the AWSCloud9User (preferred) or AWSCloud9Administrator managed policy attached.

import iam "github.com/aws/aws-cdk-go/awscdk"

var vpc Vpc

cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
	Owner: cloud9.Owner_AssumedRole(awscdk.*stack_Of(this).Account, jsii.String("Admin/johndoe-role")),
})

Auto-Hibernation

A Cloud9 environment can automatically start and stop the associated EC2 instance to reduce costs.

Use automaticStop to specify the number of minutes until the running instance is shut down after the environment was last used.

defaultVpc := ec2.Vpc_FromLookup(this, jsii.String("DefaultVPC"), &VpcLookupOptions{
	IsDefault: jsii.Boolean(true),
})
cloud9.NewEc2Environment(this, jsii.String("Cloud9Env2"), &Ec2EnvironmentProps{
	Vpc: defaultVpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
	AutomaticStop: awscdk.Duration_Minutes(jsii.Number(30)),
})

Documentation

Overview

The CDK Construct Library for AWS::Cloud9

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ec2Environment_IsConstruct

func Ec2Environment_IsConstruct(x interface{}) *bool

Checks if `x` is a construct.

Use this method instead of `instanceof` to properly detect `Construct` instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the `constructs` library on disk are seen as independent, completely different libraries. As a consequence, the class `Construct` in each copy of the `constructs` library is seen as a different class, and an instance of one class will not test as `instanceof` the other class. `npm install` will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the `constructs` library can be accidentally installed, and `instanceof` will behave unpredictably. It is safest to avoid using `instanceof`, and using this type-testing method instead.

Returns: true if `x` is an object created from a class which extends `Construct`. Experimental.

func Ec2Environment_IsOwnedResource

func Ec2Environment_IsOwnedResource(construct constructs.IConstruct) *bool

Returns true if the construct was created by CDK, and false otherwise. Experimental.

func Ec2Environment_IsResource

func Ec2Environment_IsResource(construct constructs.IConstruct) *bool

Check whether the given construct is a Resource. Experimental.

func Ec2Environment_PROPERTY_INJECTION_ID

func Ec2Environment_PROPERTY_INJECTION_ID() *string

func NewEc2Environment_Override

func NewEc2Environment_Override(e Ec2Environment, scope constructs.Construct, id *string, props *Ec2EnvironmentProps)

Experimental.

Types

type CloneRepository

type CloneRepository interface {
	// Experimental.
	PathComponent() *string
	// Experimental.
	RepositoryUrl() *string
}

The class for different repository providers.

Example:

import "github.com/aws/aws-cdk-go/awscdk"

// create a new Cloud9 environment and clone the two repositories
var vpc Vpc

// create a codecommit repository to clone into the cloud9 environment
repoNew := codecommit.NewRepository(this, jsii.String("RepoNew"), &RepositoryProps{
	RepositoryName: jsii.String("new-repo"),
})

// import an existing codecommit repository to clone into the cloud9 environment
repoExisting := codecommit.Repository_FromRepositoryName(this, jsii.String("RepoExisting"), jsii.String("existing-repo"))
cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ClonedRepositories: []CloneRepository{
		cloud9.CloneRepository_FromCodeCommit(repoNew, jsii.String("/src/new-repo")),
		cloud9.CloneRepository_*FromCodeCommit(repoExisting, jsii.String("/src/existing-repo")),
	},
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
})

Experimental.

func CloneRepository_FromCodeCommit

func CloneRepository_FromCodeCommit(repository awscodecommit.IRepository, path *string) CloneRepository

import repository to cloud9 environment from AWS CodeCommit. Experimental.

type ConnectionType

type ConnectionType string

The connection type used for connecting to an Amazon EC2 environment. Experimental.

const (
	// Connect through SSH.
	// Experimental.
	ConnectionType_CONNECT_SSH ConnectionType = "CONNECT_SSH"
	// Connect through AWS Systems Manager When using SSM, service role and instance profile aren't automatically created.
	//
	// See https://docs.aws.amazon.com/cloud9/latest/user-guide/ec2-ssm.html#service-role-ssm
	// Experimental.
	ConnectionType_CONNECT_SSM ConnectionType = "CONNECT_SSM"
)

type Ec2Environment

type Ec2Environment interface {
	awscdk.Resource
	IEc2Environment
	// The environment ARN of this Cloud9 environment.
	// Experimental.
	Ec2EnvironmentArn() *string
	// The environment name of this Cloud9 environment.
	// Experimental.
	Ec2EnvironmentName() *string
	// The environment this resource belongs to.
	//
	// For resources that are created and managed in a Stack (those created by
	// creating new class instances like `new Role()`, `new Bucket()`, etc.), this
	// is always the same as the environment of the stack they belong to.
	//
	// For referenced resources (those obtained from referencing methods like
	// `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
	// different than the stack they were imported into.
	// Experimental.
	Env() *interfaces.ResourceEnvironment
	// The environment ID of this Cloud9 environment.
	// Experimental.
	EnvironmentId() *string
	// The complete IDE URL of this Cloud9 environment.
	// Experimental.
	IdeUrl() *string
	// The tree node.
	// Experimental.
	Node() constructs.Node
	// Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.
	//
	// This value will resolve to one of the following:
	// - a concrete value (e.g. `"my-awesome-bucket"`)
	// - `undefined`, when a name should be generated by CloudFormation
	// - a concrete name generated automatically during synthesis, in
	//   cross-environment scenarios.
	// Experimental.
	PhysicalName() *string
	// The stack in which this resource is defined.
	// Experimental.
	Stack() awscdk.Stack
	// VPC ID.
	// Experimental.
	Vpc() awsec2.IVpc
	// Apply the given removal policy to this resource.
	//
	// The Removal Policy controls what happens to this resource when it stops
	// being managed by CloudFormation, either because you've removed it from the
	// CDK application or because you've made a change that requires the resource
	// to be replaced.
	//
	// The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
	// account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).
	// Experimental.
	ApplyRemovalPolicy(policy awscdk.RemovalPolicy)
	// Experimental.
	GeneratePhysicalName() *string
	// Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. `bucket.bucketArn`).
	//
	// Normally, this token will resolve to `arnAttr`, but if the resource is
	// referenced across environments, `arnComponents` will be used to synthesize
	// a concrete ARN with the resource's physical name. Make sure to reference
	// `this.physicalName` in `arnComponents`.
	// Experimental.
	GetResourceArnAttribute(arnAttr *string, arnComponents *awscdk.ArnComponents) *string
	// Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. `bucket.bucketName`).
	//
	// Normally, this token will resolve to `nameAttr`, but if the resource is
	// referenced across environments, it will be resolved to `this.physicalName`,
	// which will be a concrete name.
	// Experimental.
	GetResourceNameAttribute(nameAttr *string) *string
	// Returns a string representation of this construct.
	// Experimental.
	ToString() *string
	// Applies one or more mixins to this construct.
	//
	// Mixins are applied in order. The list of constructs is captured at the
	// start of the call, so constructs added by a mixin will not be visited.
	// Use multiple `with()` calls if subsequent mixins should apply to added
	// constructs.
	// Experimental.
	With(mixins ...constructs.IMixin) constructs.IConstruct
}

A Cloud9 Environment with Amazon EC2.

Example:

import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc

user := iam.NewUser(this, jsii.String("user"))
user.AddManagedPolicy(iam.ManagedPolicy_FromAwsManagedPolicyName(jsii.String("AWSCloud9Administrator")))
cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,

	Owner: cloud9.Owner_User(user),
})

Experimental.

func NewEc2Environment

func NewEc2Environment(scope constructs.Construct, id *string, props *Ec2EnvironmentProps) Ec2Environment

Experimental.

type Ec2EnvironmentProps

type Ec2EnvironmentProps struct {
	// The image ID used for creating an Amazon EC2 environment.
	// Experimental.
	ImageId ImageId `field:"required" json:"imageId" yaml:"imageId"`
	// The VPC that AWS Cloud9 will use to communicate with the Amazon Elastic Compute Cloud (Amazon EC2) instance.
	// Experimental.
	Vpc awsec2.IVpc `field:"required" json:"vpc" yaml:"vpc"`
	// The number of minutes until the running instance is shut down after the environment was last used.
	//
	// Setting a value of 0 means the instance will never be automatically shut down."
	// Default: - The instance will not be shut down automatically.
	//
	// Experimental.
	AutomaticStop awscdk.Duration `field:"optional" json:"automaticStop" yaml:"automaticStop"`
	// The AWS CodeCommit repository to be cloned.
	// Default: - do not clone any repository.
	//
	// Experimental.
	ClonedRepositories *[]CloneRepository `field:"optional" json:"clonedRepositories" yaml:"clonedRepositories"`
	// The connection type used for connecting to an Amazon EC2 environment.
	//
	// Valid values are: CONNECT_SSH (default) and CONNECT_SSM (connected through AWS Systems Manager).
	// Default: - CONNECT_SSH.
	//
	// Experimental.
	ConnectionType ConnectionType `field:"optional" json:"connectionType" yaml:"connectionType"`
	// Description of the environment.
	// Default: - no description.
	//
	// Experimental.
	Description *string `field:"optional" json:"description" yaml:"description"`
	// Name of the environment.
	// Default: - automatically generated name.
	//
	// Experimental.
	Ec2EnvironmentName *string `field:"optional" json:"ec2EnvironmentName" yaml:"ec2EnvironmentName"`
	// The type of instance to connect to the environment.
	// Default: - t2.micro
	//
	// Experimental.
	InstanceType awsec2.InstanceType `field:"optional" json:"instanceType" yaml:"instanceType"`
	// Owner of the environment.
	//
	// The owner has full control of the environment and can invite additional members.
	// Default: - The identity that CloudFormation executes under will be the owner.
	//
	// Experimental.
	Owner Owner `field:"optional" json:"owner" yaml:"owner"`
	// The subnetSelection of the VPC that AWS Cloud9 will use to communicate with the Amazon EC2 instance.
	// Default: - all public subnets of the VPC are selected.
	//
	// Experimental.
	SubnetSelection *awsec2.SubnetSelection `field:"optional" json:"subnetSelection" yaml:"subnetSelection"`
}

Properties for Ec2Environment.

Example:

import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc

user := iam.NewUser(this, jsii.String("user"))
user.AddManagedPolicy(iam.ManagedPolicy_FromAwsManagedPolicyName(jsii.String("AWSCloud9Administrator")))
cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,

	Owner: cloud9.Owner_User(user),
})

Experimental.

type IEc2Environment

type IEc2Environment interface {
	awscdk.IResource
	// The arn of the EnvironmentEc2.
	// Experimental.
	Ec2EnvironmentArn() *string
	// The name of the EnvironmentEc2.
	// Experimental.
	Ec2EnvironmentName() *string
}

A Cloud9 Environment. Experimental.

func Ec2Environment_FromEc2EnvironmentName

func Ec2Environment_FromEc2EnvironmentName(scope constructs.Construct, id *string, ec2EnvironmentName *string) IEc2Environment

import from EnvironmentEc2Name. Experimental.

type ImageId

type ImageId string

The image ID used for creating an Amazon EC2 environment.

Example:

import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc

user := iam.NewUser(this, jsii.String("user"))
user.AddManagedPolicy(iam.ManagedPolicy_FromAwsManagedPolicyName(jsii.String("AWSCloud9Administrator")))
cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,

	Owner: cloud9.Owner_User(user),
})

Experimental.

const (
	// Create using Amazon Linux 2.
	// Experimental.
	ImageId_AMAZON_LINUX_2 ImageId = "AMAZON_LINUX_2"
	// Create using Amazon Linux 2023.
	// Experimental.
	ImageId_AMAZON_LINUX_2023 ImageId = "AMAZON_LINUX_2023"
	// Create using Ubuntu 18.04.
	// Deprecated: Since Ubuntu 18.04 has ended standard support as of May 31, 2023, we recommend you choose Ubuntu 22.04.
	ImageId_UBUNTU_18_04 ImageId = "UBUNTU_18_04"
	// Create using Ubuntu 22.04.
	// Experimental.
	ImageId_UBUNTU_22_04 ImageId = "UBUNTU_22_04"
)

type Owner

type Owner interface {
	// of environment owner.
	// Experimental.
	OwnerArn() *string
}

An environment owner.

Example:

import iam "github.com/aws/aws-cdk-go/awscdk"

var vpc Vpc

cloud9.NewEc2Environment(this, jsii.String("C9Env"), &Ec2EnvironmentProps{
	Vpc: Vpc,
	ImageId: cloud9.ImageId_AMAZON_LINUX_2,
	Owner: cloud9.Owner_FederatedUser(awscdk.*stack_Of(this).Account, jsii.String("Admin/johndoe")),
})

Experimental.

func Owner_AccountRoot

func Owner_AccountRoot(accountId *string) Owner

Make the Account Root User the environment owner (not recommended). Experimental.

func Owner_AssumedRole

func Owner_AssumedRole(accountId *string, roleName *string) Owner

Make an IAM assumed role the environment owner. Experimental.

func Owner_FederatedUser

func Owner_FederatedUser(accountId *string, userName *string) Owner

Make an IAM federated user the environment owner. Experimental.

func Owner_User

func Owner_User(user awsiam.IUser) Owner

Make an IAM user the environment owner.

User need to have AWSCloud9Administrator permissions. See: https://docs.aws.amazon.com/cloud9/latest/user-guide/share-environment.html#share-environment-about

Experimental.

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL