Qwertford
Qwertford

Reputation: 1189

Can't create IAM role with bash on ubuntu

Im trying to create an IAM role with bash in ubuntu following this tutorial to create a lambdaless data api with aws. However im struggling to create the IAM role through the bash script.

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

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

Which returns the error:

aws: error: argument --profile: expected one argument
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]

The two changes I made were:

. ./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}

The changes I made were because I have the common variables file in the same directory as this script.

Upvotes: 0

Views: 377

Answers (1)

Rodrigo Murillo
Rodrigo Murillo

Reputation: 13648

Your ${profile} variable is not properly defined. It is evaluating as an empty string. Try to echo that value at the top of the script to confirm.

Upvotes: 1

Related Questions