This documentation is for Version 1 of the Amazon CLI only. For documentation related to Version 2 of the Amazon CLI, see the Version 2 User Guide.
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.
Each example includes a link to the complete source code, 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-connectionexample 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-typeBitbucket\ --connection-nameMyConnectionOutput:
{ "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. -
For API details, see CreateConnection
in Amazon CLI Command Reference.
-
The following code example shows how to use create-host.
- Amazon CLI
-
To create a host
The following
create-hostexample 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 \ --nameMyHost\ --provider-typeGitHubEnterpriseServer\ --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-connectionexample shows how to delete a connection.aws codestar-connections delete-connection \ --connection-arnarn:aws:codestar-connections:us-west-2:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441fThis command produces no output.
For more information, see Delete a connection (CLI)
in the Developer Tools console User Guide. -
For API details, see DeleteConnection
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-host.
- Amazon CLI
-
To delete a host
The following
delete-hostexample 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-connectionexample shows details about a connection.aws codestar-connections get-connection \ --connection-arnarn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441fOutput:
{ "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-hostexample shows details about a host:aws codestar-connections get-host \ --host-arnarn:aws:codestar-connections:us-east-1:123456789012:host/MyHost-28aef605Output:
{ "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-connectionsexample retrieves a list of all connections in your account for the Bitbucket provider type.:aws codestar-connections list-connections \ --provider-typeBitbucket\ --max-results5\ --next-token: next-tokenOutput:
{ "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. -
For API details, see ListConnections
in Amazon CLI Command Reference.
-
The following code example shows how to use list-hosts.
- Amazon CLI
-
To list hosts
The following
list-hostsexample retrieves a list of all hosts in your account.aws codestar-connections list-hostsOutput:
{ "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-resourceexample retrieves a list of all tags attached to the specified connections resource.aws codestar-connections list-tags-for-resource \ --resource-arnarn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441fOutput:
{ "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. -
For API details, see ListTagsForResource
in Amazon CLI Command Reference.
-
The following code example shows how to use tag-resource.
- Amazon CLI
-
To tag a resource
The following
tag-resourceexample associates a set of provided tags with a connection. Use this command to add or edit tags.aws codestar-connections tag-resource \ --resource-arnarn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f\ --tagsKey=Project,Value=ProjectAKey=IscontainerBased,Value=trueThis 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-resourceremoves a tag from the specified resource.aws codestar-connections untag-resource \ --resource-arnarn:aws:codestar-connections:us-east-1:123456789012:connection/aEXAMPLE-8aad-4d5d-8878-dfcab0bc441f\ --tag-keysProjectReadOnlyOutput:
{ "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.
-