CodeConnections examples using Amazon CLI - Amazon Command Line Interface
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

CodeConnections examples using Amazon CLI

The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with CodeConnections.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use create-connection.

Amazon CLI

To create a connection

The following create-connection example shows how to create a connection to a third-party repository. This example creates a connection where the third-party provider is Bitbucket.

A connection created through the Amazon CLI or Amazon CloudFormation is in Pending status by default. After you create a connection with the CLI or Amazon CloudFormation, use the console to edit the connection to make its status Available.

aws codestar-connections create-connection \ --provider-type Bitbucket \ --connection-name MyConnection

Output:

{ "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f" }

For more information, see Create a connection in the Developer Tools console User Guide.

The following code example shows how to use create-host.

Amazon CLI

To create a host

The following create-host example shows how to create a host to represent the endpoint for the infrastructure where your third-party provider is installed. This example creates a host where the third-party installed provider is GitHub Enterprise Server.

A host created through the Amazon CLI is in Pending status by default. After you create a host with the CLI, use the console or the CLI to set up the host to make its status Available.

aws codestar-connections create-host \ --name MyHost \ --provider-type GitHubEnterpriseServer \ --provider-endpoint "https://my-instance.dev"

Output:

{ "HostArn": "arn:aws:codestar-connections:us-east-1:123456789012:host/My-Host-28aef605" }

For more information, see Create a host (CLI) in the Developer Tools console User Guide.

  • For API details, see CreateHost in Amazon CLI Command Reference.

The following code example shows how to use delete-connection.

Amazon CLI

To delete a connection

The following delete-connection example shows how to delete a connection.

aws codestar-connections delete-connection \ --connection-arn arn:aws:codestar-connections:us-west-2:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f

This command produces no output.

For more information, see Delete a connection (CLI) in the Developer Tools console User Guide.

The following code example shows how to use delete-host.

Amazon CLI

To delete a host

The following delete-host example shows how to delete a host. Before you can delete a host, you must delete all connections associated with the host.

aws codestar-connections delete-host \ --host-arn "arn:aws:codestar-connections:us-east-1 :123456789012:host/My-Host-28aef605"

This command produces no output.

For more information, see Delete a host (CLI) in the Developer Tools console User Guide.

  • For API details, see DeleteHost in Amazon CLI Command Reference.

The following code example shows how to use get-connection.

Amazon CLI

To get information about a connection

The following get-connection example shows details about a connection.

aws codestar-connections get-connection \ --connection-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f

Output:

{ "Connection": { "ConnectionName": "MyConnection", "ConnectionArn": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f", "ProviderType": "Bitbucket", "OwnerAccountId": "123456789012", "ConnectionStatus": "AVAILABLE" } }

For more information, see View connection details in the Developer Tools console User Guide.

  • For API details, see GetConnection in Amazon CLI Command Reference.

The following code example shows how to use get-host.

Amazon CLI

To get information about a host

The following get-host example shows details about a host:

aws codestar-connections get-host \ --host-arn arn:aws:codestar-connections:us-east-1:123456789012:host/MyHost-28aef605

Output:

{ "Name": "MyHost", "Status": "AVAILABLE", "ProviderType": "GitHubEnterpriseServer", "ProviderEndpoint": "https://test-instance-1.dev/" }

For more information, see View host details (CLI) in the Developer Tools console User Guide.

  • For API details, see GetHost in Amazon CLI Command Reference.

The following code example shows how to use list-connections.

Amazon CLI

To list connections

The following list-connections example retrieves a list of all connections in your account for the Bitbucket provider type.:

aws codestar-connections list-connections \ --provider-type Bitbucket \ --max-results 5 \ --next-token: next-token

Output:

{ "Connections": [ { "ConnectionName": "my-connection", "ProviderType": "Bitbucket", "Status": "PENDING", "ARN": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f", "OwnerAccountId": "123456789012" }, { "ConnectionName": "my-other-connection", "ProviderType": "Bitbucket", "Status": "AVAILABLE", "ARN": "arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f", "OwnerAccountId": "123456789012" }, ], "NextToken": "next-token" }

For more information, see List connections (CLI) in the Developer Tools console User Guide.

The following code example shows how to use list-hosts.

Amazon CLI

To list hosts

The following list-hosts example retrieves a list of all hosts in your account.

aws codestar-connections list-hosts

Output:

{ "Hosts": [ { "Name": "My-Host", "HostArn": "arn:aws:codestar-connections:us-east-1:123456789012:host/My-Host-28aef605", "ProviderType": "GitHubEnterpriseServer", "ProviderEndpoint": "https://my-instance.test.dev", "Status": "AVAILABLE" } ] }

For more information, see List hosts (CLI) in the Developer Tools console User Guide.

  • For API details, see ListHosts in Amazon CLI Command Reference.

The following code example shows how to use list-tags-for-resource.

Amazon CLI

To list tags

The following list-tags-for-resource example retrieves a list of all tags attached to the specified connections resource.

aws codestar-connections list-tags-for-resource \ --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f

Output:

{ "Tags": [ { "Key": "Project", "Value": "ProjectA" }, { "Key": "ReadOnly", "Value": "true" } ] }

For more information, see View tags for a connections resource in the Developer Tools console User Guide.

The following code example shows how to use tag-resource.

Amazon CLI

To tag a resource

The following tag-resource example associates a set of provided tags with a connection. Use this command to add or edit tags.

aws codestar-connections tag-resource \ --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f \ --tags Key=Project,Value=ProjectA Key=IscontainerBased,Value=true

This command produces no output.

For more information, see Add tags to a connections resource in the Developer Tools console User Guide.

  • For API details, see TagResource in Amazon CLI Command Reference.

The following code example shows how to use untag-resource.

Amazon CLI

To remove Amazon tags from a connections resource

The following untag-resource removes a tag from the specified resource.

aws codestar-connections untag-resource \ --resource-arn arn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f \ --tag-keys Project ReadOnly

Output:

{ "Tags": [] }

For more information, see Remove tags from a connections resource in the Developer Tools console User Guide.

  • For API details, see UntagResource in Amazon CLI Command Reference.