使用 cicd 管道对 cloudformation 导入现有资源的 S3 访问被拒绝

S3 access denied for cloudformation import existing resources using the cicd pipeline

我已经创建了一个 cicd 管道来导入 cloudformation 中的现有资源。我想导入现有的 S3 存储桶并对其进行加密,仅通过代码管道。我使用了 codebuild 和 codepipeline,但在 运行 buildspec.yaml:

时出现错误

An error occurred (ValidationError) when calling the CreateChangeSet operation: S3 error: Access Denied

我可以使用控制台导入和处理相同的东西,并且我在 codepipeline 和 codebuild 角色中添加了访问权限。

我的 buildspec.yml 部署了以下命令:

- aws cloudformation create-change-set --stack-name ${STACK_NAME} --change-set-name ImportChangeSet --change-set-type IMPORT --resources-to-import file://ResourcesToImport.txt --template-url https://Bucket_Name.s3.eu-west-3.amazonaws.com/templates/Template_Import.yaml

无法解决上述错误的朋友: 我尝试使用 --template-body 而不是 --template-url 并且它起作用了,因为我在 cli 命令中提供的 url 存在问题。所以上面的命令改为:

aws cloudformation create-change-set --stack-name ${STACK_NAME} --change-set-name ImportChangeSet --change-set-type IMPORT --resources-to-import "[{\"ResourceType\":\"AWS::S3::Bucket\",\"LogicalResourceId\":\"ImportedS3Bucket\",\"ResourceIdentifier\":{\"BucketName\":\"${Bucket_Name}\"}}]"
--template-body file://templates/template.yaml --capabilities CAPABILITY_NAMED_IAM