-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Resources:
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html
Amazon API Gateway resource policies are JSON policy documents that you attach to an API to control whether a specified principal (typically an IAM user or role) can invoke the API. You can use API Gateway resource policies to allow your API to be securely invoked by:
-
users from a specified AWS account
-
specified source IP address ranges or CIDR blocks
-
specified virtual private clouds (VPCs) or VPC endpoints (in any account)
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
...
Auth:
ResourcePolicy:
# IAM-based policies
IAMAllowlist: [
'123456789012:role/myRole',
'${AWS::AccountId}:user/myUser',
'123456789012:root',
'123456789012:*'
],
IAMDenylist: [],
# IP-based policies
IpAllowlist: ['12.123.234.213'],
IpDenylist: [],
# VPC-based policies
SourceVpcAllowlist: ['vpc-ab1234cd'],
SourceVpcDenylist: []
# Custom statements. These must be actual Resource Policy Statements.
CustomStatements: [{
Action: 'execute-api:Invoke', # Optional; Default: execute-api:Invoke
Resource: ['execute-api:/*/*/*'], # Optional; constructed based on Stagename, Path, and Method.
... # Additional properties get passed through to the resulting statement
}]
MyFn:
Type: AWS::Serverless::Function
Properties:
Events:
GetRoot:
Type: Api
Properties:
Auth:
ResourcePolicy:
... # Same as above; the Statement Resource will be created differently when defined here (i.e. it will use the Method and Path)When Auth.ResourcePolicy is set on an API Event, the Path and Method of the Event will be used to construct the Resource. When Auth.ResourcePolicy is set on an API resource, the Path and Method parts of Resource will be *; that is, the policy will apply to the entire API. For the Stage part of Resource, we can inject the StageName, however, we do need to consider how we will make it work when we implement multi-stage support.
Note that Event ResourcePolicy and API Resource ResourcePolicy are combined to create the final ResourcePolicy.