无法在 ubuntu 上使用 bash 创建 IAM 角色



im试图在本教程之后在ubuntu中创建一个IAM角色,以创建带有AWS的lambdaless数据API。但是,我正在努力通过bash脚本创建IAM角色。

https://hackernoon.com/serverless-and-and-lambdaless-scalable-crud-data-api-with-with-with-with-api-api-gateway---dynamodb-62616161008bb2

#!/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}

我所做的更改是因为我在与此脚本相同的目录中具有共同的变量文件。

您的${profile}变量未正确定义。它正在评估为一个空字符串。尝试在脚本的顶部回声以确认该值。

相关内容

  • 没有找到相关文章

最新更新