我尝试按照本教程在 ubuntu 中使用 bash 创建一个 IAM 角色,以使用 aws 创建一个无 lambda 数据 api。但是,我正在努力通过 bash 脚本创建 IAM 角色。
#!/bin/sh
. ./common-variables.sh
#Setup API Gateway Role
role_name=api-gateway-dynamo-full-user-comments
aws iam create-role --role-name ${role_name} \
--assume-role-policy-document file://../../IAM/assume-role-api-gateway.json --profile $profile
#Add Policy for API Gateway to write to logs
role_policy_arn="arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
aws iam attach-role-policy \
--role-name "${role_name}" \
--policy-arn "${role_policy_arn}" --profile ${profile}
#Create DynamoDB Policy
policy_name="dynamo-full-user-visits-api"
aws iam create-policy --policy-name ${policy_name} --policy-document file://../../IAM/dynamo-full-user-comments.json --profile ${profile}
#Attach Policy for API Gateway to access DynamoDB
role_policy_arn="arn:aws:iam::${aws_account_id}:policy/${policy_name}"
aws iam attach-role-policy \
--role-name "${role_name}" \
--policy-arn "${role_policy_arn}" --profile ${profile}
返回错误:
aws: error: argument --profile: expected one argument
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
我所做的两个更改是:
. ./common-variables.sh->common-variables.sh
aws iam create-policy --policy-name ${policy_name} --policy-document file://../../IAM/dynamo-full-user-comments.json --profile ${profile}
->aws iam create-policy --policy-name ${policy_name} --policy-document file:IAM/dynamo-full-user-comments.json --profile ${profile}
我所做的更改是因为我在与此脚本相同的目录中有公共变量文件。