AWS CodeStar 使用示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

AWS CodeStar 使用示例 Amazon CLI

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 AWS CodeStar。 Amazon Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 associate-team-member

Amazon CLI

向项目添加团队成员

以下associate-team-member示例使用指定 ID intern 使用户成为项目的查看者。

aws codestar associate-team-member \ --project-id my-project \ --user-arn arn:aws:iam::123456789012:user/intern \ --project-role Viewer

此命令不生成任何输出。

以下代码示例演示如何使用 create-project

Amazon CLI

创建项目

以下create-project示例使用 JSON 输入文件创建 CodeStar 项目。

aws codestar create-project \ --cli-input-json file://create-project.json

create-project.json 的内容:

{ "name": "Custom Project", "id": "custom-project", "sourceCode": [ { "source": { "s3": { "bucketName": "codestar-artifacts", "bucketKey": "nodejs-function.zip" } }, "destination": { "codeCommit": { "name": "codestar-custom-project" } } } ], "toolchain": { "source": { "s3": { "bucketName": "codestar-artifacts", "bucketKey": "toolchain.yml" } }, "roleArn": "arn:aws:iam::123456789012:role/service-role/aws-codestar-service-role", "stackParameters": { "ProjectId": "custom-project" } } }

输出:

{ "id": "my-project", "arn": "arn:aws:codestar:us-east-2:123456789012:project/custom-project" }

有关包含自定义项目的示例代码和模板的教程,请参阅《< https://docs.aws.amazon.com/codestar/latest/userguide/cli-tutorial.html > Amazon CodeStar 用户指南》中的 “ Amazon CodeStar Amazon 使用 CLI 创建项目”。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateProject中的。

以下代码示例演示如何使用 create-user-profile

Amazon CLI

创建用户个人资料

以下create-user-profile示例为具有指定 ARN 的 IAM 用户创建用户个人资料。

aws codestar create-user-profile \ --user-arn arn:aws:iam::123456789012:user/intern \ --display-name Intern \ --email-address intern@example.com

输出:

{ "userArn": "arn:aws:iam::123456789012:user/intern", "displayName": "Intern", "emailAddress": "intern@example.com", "sshPublicKey": "", "createdTimestamp": 1572552308.607, "lastModifiedTimestamp": 1572552308.607 }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateUserProfile中的。

以下代码示例演示如何使用 delete-project

Amazon CLI

删除项目

以下delete-project示例删除了指定的项目。

aws codestar delete-project \ --project-id my-project

输出:

{ "projectArn": "arn:aws:codestar:us-east-2:123456789012:project/my-project" }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteProject中的。

以下代码示例演示如何使用 delete-user-profile

Amazon CLI

删除用户个人资料

以下delete-user-profile示例删除具有指定 ARN 的用户的用户配置文件。

aws codestar delete-user-profile \ --user-arn arn:aws:iam::123456789012:user/intern

输出:

{ "userArn": "arn:aws:iam::123456789012:user/intern" }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteUserProfile中的。

以下代码示例演示如何使用 describe-project

Amazon CLI

查看项目

以下describe-project示例检索有关指定项目的详细信息。

aws codestar describe-project \ --id my-project

输出:

{ "name": "my project", "id": "my-project", "arn": "arn:aws:codestar:us-west-2:123456789012:project/my-project", "description": "My first CodeStar project.", "createdTimeStamp": 1572547510.128, "status": { "state": "CreateComplete" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeProject中的。

以下代码示例演示如何使用 describe-user-profile

Amazon CLI

查看用户个人资料

以下describe-user-profile示例检索有关具有指定 ARN 的用户的用户个人资料的详细信息。

aws codestar describe-user-profile \ --user-arn arn:aws:iam::123456789012:user/intern

输出:

{ "userArn": "arn:aws:iam::123456789012:user/intern", "displayName": "Intern", "emailAddress": "intern@example.com", "sshPublicKey": "intern", "createdTimestamp": 1572552308.607, "lastModifiedTimestamp": 1572553495.47 }

以下代码示例演示如何使用 disassociate-team-member

Amazon CLI

移除团队成员

以下disassociate-team-member示例将具有指定 ARN 的用户从项目中移除。my-project

aws codestar disassociate-team-member \ --project-id my-project \ --user-arn arn:aws:iam::123456789012:user/intern

此命令不生成任何输出。

以下代码示例演示如何使用 list-projects

Amazon CLI

查看项目

以下list-projects示例检索当前区域中的项目列表。

aws codestar list-projects

输出:

{ "projects": [ { "projectId": "intern-projects", "projectArn": "arn:aws:codestar:us-west-2:123456789012:project/intern-projects" }, { "projectId": "my-project", "projectArn": "arn:aws:codestar:us-west-2:123456789012:project/my-project" } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListProjects中的。

以下代码示例演示如何使用 list-resources

Amazon CLI

查看资源

以下list-resources示例检索指定项目的资源列表。

aws codestar list-resources \ --id my-project

输出:

{ "resources": [ { "id": "arn:aws:execute-api:us-east-2:123456789012:r3wxmplbv8" }, { "id": "arn:aws:codedeploy:us-east-2:123456789012:application:awscodestar-my-project-lambda-ServerlessDeploymentApplication-PF0LXMPL1KA0" }, { "id": "arn:aws:s3:::aws-codestar-us-east-2-123456789012-my-project-pipe" }, { "id": "arn:aws:lambda:us-east-2:123456789012:function:awscodestar-my-project-lambda-GetHelloWorld-16W3LVXMPLNNS" }, { "id": "arn:aws:cloudformation:us-east-2:123456789012:stack/awscodestar-my-project-lambda/b4904ea0-fc20-xmpl-bec6-029123b1cc42" }, { "id": "arn:aws:cloudformation:us-east-2:123456789012:stack/awscodestar-my-project/1b133f30-fc20-xmpl-a93a-0688c4290cb8" }, { "id": "arn:aws:iam::123456789012:role/CodeStarWorker-my-project-ToolChain" }, { "id": "arn:aws:iam::123456789012:policy/CodeStar_my-project_PermissionsBoundary" }, { "id": "arn:aws:s3:::aws-codestar-us-east-2-123456789012-my-project-app" }, { "id": "arn:aws:codepipeline:us-east-2:123456789012:my-project-Pipeline" }, { "id": "arn:aws:codedeploy:us-east-2:123456789012:deploymentgroup:my-project/awscodestar-my-project-lambda-GetHelloWorldDeploymentGroup-P7YWXMPLT0QB" }, { "id": "arn:aws:iam::123456789012:role/CodeStar-my-project-Execution" }, { "id": "arn:aws:iam::123456789012:role/CodeStarWorker-my-project-CodeDeploy" }, { "id": "arn:aws:codebuild:us-east-2:123456789012:project/my-project" }, { "id": "arn:aws:iam::123456789012:role/CodeStarWorker-my-project-CloudFormation" }, { "id": "arn:aws:codecommit:us-east-2:123456789012:Go-project" } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListResources中的。

以下代码示例演示如何使用 list-tags-for-project

Amazon CLI

查看项目的标签

以下list-tags-for-project示例检索附加到指定项目的标签。

aws codestar list-tags-for-project \ --id my-project

输出:

{ "tags": { "Department": "Marketing", "Team": "Website" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListTagsForProject中的。

以下代码示例演示如何使用 list-team-members

Amazon CLI

查看团队成员列表

以下list-team-members示例检索与指定项目关联的用户列表。

aws codestar list-team-members \ --project-id my-project

输出:

{ "teamMembers": [ { "userArn": "arn:aws:iam::123456789012:user/admin", "projectRole": "Owner", "remoteAccessAllowed": false }, { "userArn": "arn:aws:iam::123456789012:user/intern", "projectRole": "Contributor", "remoteAccessAllowed": false } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListTeamMembers中的。

以下代码示例演示如何使用 list-user-profiles

Amazon CLI

查看用户个人资料列表

以下list-user-profiles示例检索当前区域中所有用户个人资料的列表。

aws codestar list-user-profiles

输出:

{ "userProfiles": [ { "userArn": "arn:aws:iam::123456789012:user/admin", "displayName": "me", "emailAddress": "me@example.com", "sshPublicKey": "" }, { "userArn": "arn:aws:iam::123456789012:user/intern", "displayName": "Intern", "emailAddress": "intern@example.com", "sshPublicKey": "intern" } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListUserProfiles中的。

以下代码示例演示如何使用 tag-project

Amazon CLI

将标签附加到项目

以下tag-project示例向指定项目添加名为Department且值Marketing为的标签。

aws codestar tag-project \ --id my-project \ --tags Department=Marketing

输出:

{ "tags": { "Department": "Marketing" } }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考TagProject中的。

以下代码示例演示如何使用 untag-project

Amazon CLI

从项目中移除标签

以下untag-project示例Team从指定项目中移除所有密钥名称为的标签。

aws codestar untag-project \ --id my-project \ --tags Team

此命令不生成任何输出。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UntagProject中的。

以下代码示例演示如何使用 update-project

Amazon CLI

更新项目

以下update-project示例为指定项目添加了描述。

aws codestar update-project \ --id my-project \ --description "My first CodeStar project"

此命令不生成任何输出。

  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateProject中的。

以下代码示例演示如何使用 update-team-member

Amazon CLI

修改团队成员

以下update-team-member示例使指定用户成为项目的贡献者,并授予他们对项目资源的远程访问权限。

aws codestar update-team-member \ --project-id my-project \ --user-arn arn:aws:iam::123456789012:user/intern \ --project-role Contributor -\ --remote-access-allowed

输出:

{ "userArn": "arn:aws:iam::123456789012:user/intern", "projectRole": "Contributor", "remoteAccessAllowed": true }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateTeamMember中的。

以下代码示例演示如何使用 update-user-profile

Amazon CLI

修改用户配置文件

以下update-user-profile示例将指定的 SHH 密钥添加到指定用户。

aws codestar update-user-profile \ --ssh-public-key intern \ --user-arn arn:aws:iam::123456789012:user/intern

输出:

{ "userArn": "arn:aws:iam::123456789012:user/intern", "displayName": "Intern", "emailAddress": "intern@example.com", "sshPublicKey": "intern", "createdTimestamp": 1572552308.607, "lastModifiedTimestamp": 1572553495.47 }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateUserProfile中的。