user/terraform未被授权对资源:执行:ssm:SendCommand



我正在编写一个github操作工作流,将使用peterkimzz/aws-ssm-send-command@master连接到EC2实例;运行部署脚本。然而,它失败了,并出现以下错误:

AccessDeniedException: User: arn:aws:iam::<AccountNumber>:user/terraform is not authorized to perform: ssm:SendCommand on resource: arn:aws:ec2:us-east-1:<AccountNumber>:instance/*** because no identity-based policy allows the ssm:SendCommand action

我确保所有github的秘密都有有效的值。但我不明白为什么它试图以terraform用户的身份执行它。在代码中没有任何地方,我使用了terraform用户。FWIW, EC2机器是使用terraform脚本配置的。但这是一个单独的工作流程。

工作流代码
name: 'Staging Deployment Pipeline'
on:
push:
branches:
- dev
jobs:
deploy-backend:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: AWS SSM Send Command
uses: peterkimzz/aws-ssm-send-command@master
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_DEV }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
aws-region: 'us-east-1'
instance-ids: ${{ secrets.AWS_EC2_INSTANCE_ID_DEV }}
working-directory: /home/ec2-user
command: aws s3 cp s3://<BucketName>/deploy.sh /opt/v1/ && bash /opt/v1/deploy.sh

绝对是权限问题。对我来说,听起来像你用来配置EC2实例的另一个脚本已经创建了一个名为terraform的实例角色/用户,这将是实例在你运行命令时使用的,它没有所需的权限。我要在我的网站上看看它是否在那里。如果你能找到,添加ssm:SendCommand策略应该可以解决这个问题。

最新更新