Ale*_*one 6 amazon-web-services aws-codecommit aws-codepipeline
是否可以创建一个代码管道,该代码管道在另一个帐户中具有CodeCommit存储库的目标源?
我只需要这样做,我会解释这个过程。
账户 C 是您的 CodeCommit 存储库的账户。帐户 P 是您的 CodePipeline... 管道的帐户。
在帐户 P 中:
创建 AWS KMS 加密密钥并添加具有访问权限的账户 C(先决条件步骤中的此处为指南)。您还需要添加 CodePipeline 角色,如果您有 CodeBuild 和 CodeDeploy 步骤,还需要添加这些角色。
在您的 CodePipeline 工件 S3 存储桶中,您需要添加账户 C 访问权限。转到存储桶策略并添加:
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::ACCOUNTC_ID:root"
},
"Action": [
"s3:Get*",
"s3:Put*"
],
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::ACCOUNTC_ID:root"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME"
}
Run Code Online (Sandbox Code Playgroud)
更改ACCOUNTC_ID为账户 C 的账户 ID,并更改YOUR_BUCKET_NAME为 CodePipeline 工件 S3 存储桶名称。
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": [
"arn:aws:iam::ACCOUNTC_ID:role/*"
]
}
}
Run Code Online (Sandbox Code Playgroud)
再次更改ACCOUNTC_ID为帐户 C 的帐户 ID。
在账户 C:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject*",
"s3:PutObject",
"s3:PutObjectAcl",
"codecommit:ListBranches",
"codecommit:ListRepositories"
],
"Resource": [
"arn:aws:s3:::YOUR_BUCKET_NAME_IN_ACCOUNTP_FOR_CODE_PIPELINE/*"
]
},
{
"Effect": "Allow",
"Action": [
"kms:DescribeKey",
"kms:GenerateDataKey*",
"kms:Encrypt",
"kms:ReEncrypt*",
"kms:Decrypt"
],
"Resource": [
"arn:aws:kms:YOUR_KMS_ARN"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
替换上述策略中的存储桶名称和 KMS ARN。将策略另存为 CrossAccountPipelinePolicy 之类的内容。
在 AWS CLI 中 您无法在控制台中执行此操作,因此您必须使用 AWS CLI。这将使您在 AccountP 中的 CodePipeline 承担 Source 步骤中的角色,并将其转储到 S3 存储桶中以供您接下来的所有步骤使用。
aws codepipeline get-pipeline --name NameOfPipeline > pipeline.json
修改管道 json 使其看起来有点像这样并替换您需要的位:
"pipeline": {
"name": "YOUR_PIPELINE_NAME",
"roleArn": "arn:aws:iam::AccountP_ID:role/ROLE_NAME_FOR_CODE_PIPELINE",
"artifactStore": {
"type": "S3",
"location": "YOUR_BUCKET_NAME",
"encryptionKey": {
"id": "arn:aws:kms:YOUR_KMS_KEY_ARN",
"type": "KMS"
}
},
"stages": [
{
"name": "Source",
"actions": [
{
"name": "Source",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "CodeCommit",
"version": "1"
},
"runOrder": 1,
"roleArn": "arn:aws:iam::AccountC_ID:role/ROLE_NAME_WITH_CROSS_ACCOUNT_POLICY",
"configuration": {
"BranchName": "master",
"PollForSourceChanges": "false",
"RepositoryName": "YOURREPOSITORYNAME"
},
"outputArtifacts": [
{
"name": "MyApp"
}
],
"inputArtifacts": []
}
]
},
Run Code Online (Sandbox Code Playgroud)
更新管道 aws codepipeline update-pipeline --cli-input-json file://pipeline.json
通过运行管道来验证它是否有效。
| 归档时间: |
|
| 查看次数: |
999 次 |
| 最近记录: |