Reputation: 409
I am currently creating a SAM template defining an AWS API gateway. I have a path /example
which has 3 methods; GET, POST and OPTIONS. I want the POST method to have IAM authorisation but the others to be public with no authorisation. My SAM template currently looks like this:
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
Name: <API NAME>
StageName: <Stage Name>
Auth:
ApiKeyRequired: false
AddDefaultAuthorizerToCorsPreflight: false
DefaultAuthorizer: AWS_IAM
ResourcePolicy:
CustomStatements: [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::...",
]
},
"Action": "execute-api:Invoke",
"Resource": "execute-api:/<Stage Name>/POST/example"
}]
Tags:
<Key>: <Value>
DefinitionBody:
<Swagger definition>
This is however attaching IAM auth to all of the methods. How can I specify it to only be attached to one of the methods?
Thank you!
Upvotes: 0
Views: 982
Reputation: 409
As @kaustubh-khavnekar mentioned in the comments the following is required:
DefaultAuthorizer: AWS_IAM
from the Auth
section.post:
x-amazon-apigateway-auth:
type : "AWS_IAM"
get:
x-amazon-apigateway-auth:
type : "NONE"
Upvotes: 1