In AWS CLI, how do I reference a path to a JSON file that is stored on my PC's local drive?

0

I have created a JSON file todefine an IAM role, and I am now trying to create the role in AWS.In AWS CLI I typed this:

aws iam create-role --role-name TrustRole --assume-role-policy-document file:// C:\Users<username>\Documents\AWS\trustpolicy.json

But I get an error message: Unknown options: C:Users<username>DocumentsAWSfirehosetrustpolicy.json

Why can't AWS understand the path to the file? And what should I do so that AWS can get to the JSON file?

asked a month ago57 views
3 Answers
0

The error you're encountering is due to the way you've specified the file path in your AWS CLI command. When referencing a local file in AWS CLI commands, you need to use the correct syntax for file paths, especially on Windows systems.

For Windows, you should use forward slashes (/) or escaped backslashes (\) in the file path. Also, there should be no space between "file://" and the beginning of the path.

Here's the correct way to reference your local JSON file:

  1. Using forward slashes: aws iam create-role --role-name TrustRole --assume-role-policy-document file://C:/Users/<username>/Documents/AWS/trustpolicy.json

  2. Using escaped backslashes: aws iam create-role --role-name TrustRole --assume-role-policy-document file://C:\Users\<username>\Documents\AWS\trustpolicy.json

Make sure to replace <username> with your actual username.

If your path contains spaces, you should enclose the entire path in quotes:

aws iam create-role --role-name TrustRole --assume-role-policy-document "file://C:/Users/<username>/Documents/AWS/trustpolicy.json"

By using one of these formats, AWS CLI should be able to correctly interpret the file path and access your JSON file. This should resolve the "Unknown options" error you're experiencing.
Sources
IAM examples using AWS CLI - AWS SDK Code Examples
Create a role to give permissions to an IAM user - AWS Identity and Access Management

profile picture
answered a month ago
  • I already applied the advice made in the comment but that does not help. If I use backslashes, I get the "Unknown options: C:Users<username>DocumentsAWSfirehosetrustpolicy.json" error message. If I use forward slashes, I get a "[Errno 2] No such file or directory:<filepath>". I triple-verified that the path is correct. So, is it impossible for AWS to find the file?

0

hi,

navigate to the folder where your JSON file located by using simple CD command

< cd C:\Users<username>\Documents\AWS\trustpolicy.json>

than run to create an IAM Role:->

<aws iam create-role --role-name TrustRole --assume-role-policy-document file://trustpolicy.json>

This approach eliminates path issue.

OR

you can debug simply append --debug in command:

aws iam create-role --role-name TrustRole --assume-role-policy-document file://C:\Users<username>\Documents\AWS\trustpolicy.json --debug

profile picture
answered a month ago
0

Here are the correct ways to reference a local JSON file in AWS CLI on Windows:

  1. Use forward slashes instead of backslashes:
aws iam create-role --role-name TrustRole --assume-role-policy-document file://C:/Users/<username>/Documents/AWS/trustpolicy.json
  1. OR use escaped backslashes:
aws iam create-role --role-name TrustRole --assume-role-policy-document file://C:\\Users\\<username>\\Documents\\AWS\\trustpolicy.json
  1. OR if you're in the same directory as the JSON file, simply use:
aws iam create-role --role-name TrustRole --assume-role-policy-document file://trustpolicy.json

Important notes:

  • There should be no space between file:// and the path
  • The file:// prefix is required to tell AWS CLI to read from a file
  • Windows file paths with single backslashes can cause parsing issues in command-line interfaces

The easiest approach is to:

  1. Navigate to the directory containing your JSON file using cd command
  2. Use the simple file://filename.json format

This will help avoid any path-related issues.

profile pictureAWS
EXPERT
answered 20 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions