Madura Dissanayake
Madura Dissanayake

Reputation: 8759

how to replace existing policy with json file using AWS cli?

I'm trying to update policy in one of my API gateway using AWS cli and this is for automation purposes. When I try with the policy json with command, it's succeeded, but when I try to execute it with pointing a json file it's giving errors,

aws apigateway update-rest-api --rest-api-id cyasdze47d --patch-operations op=replace,path=/policy,value="file://foo.json"

error :

An error occurred (BadRequestException) when calling the UpdateRestApi operation: Invalid policy document. Please check the policy syntax and ensure that Principals are valid.

foo.json

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "execute-api:Invoke",
            "Resource": "arn:aws:execute-api:eu-west-1:123345455:cyxxxxxd/test1/*"
        }
    ]
}

Can anyone help me on how to replace existing policy with json file using AWS cli ?

Thanks

Upvotes: 0

Views: 443

Answers (1)

Marcin
Marcin

Reputation: 238957

You must strinfigy your policy first as shown in the docs.

strinfigied=$(jq tostring foo.json)

aws apigateway update-rest-api --rest-api-id cyasdze47d --patch-operations op=replace,path=/policy,value=${strinfigied} 

Upvotes: 2

Related Questions