- Newest
- Most votes
- Most comments
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:
-
Using forward slashes: aws iam create-role --role-name TrustRole --assume-role-policy-document file://C:/Users/<username>/Documents/AWS/trustpolicy.json
-
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
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
Here are the correct ways to reference a local JSON file in AWS CLI on Windows:
- 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
- OR use escaped backslashes:
aws iam create-role --role-name TrustRole --assume-role-policy-document file://C:\\Users\\<username>\\Documents\\AWS\\trustpolicy.json
- 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:
- Navigate to the directory containing your JSON file using
cd
command - Use the simple
file://filename.json
format
This will help avoid any path-related issues.
Relevant content
- asked 3 years ago
- asked 3 years ago
- AWS OFFICIALUpdated 10 months 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?