Skip to content

(aws-cdk-lib): aws-sam.CfnApi does not support auth.ResourcePolicy and other options #31518

@cobnett3

Description

@cobnett3

Describe the bug

AWS::Serverless::Api supports various auth methods.

AddApiKeyRequiredToCorsPreflight: Boolean
AddDefaultAuthorizerToCorsPreflight: Boolean
ApiKeyRequired: Boolean
Authorizers: CognitoAuthorizer | LambdaTokenAuthorizer | LambdaRequestAuthorizer
DefaultAuthorizer: String
InvokeRole: String
ResourcePolicy: ResourcePolicyStatement
UsagePlan: ApiUsagePlan

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-api-apiauth.html

However, only AddDefaultAuthorizerToCorsPreflight, Authorizers, and DefaultAuthorizer are supported.
Others such as ResourcePolicy and ApiKeyRequired are not supported.

./node_modules/aws-cdk-lib/aws-sam/lib/sam.generated.d.ts

export interface CfnApiProps {
    [...]
    /**
     * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-serverless-api.html#cfn-serverless-api-auth
     */
    readonly auth?: CfnApi.AuthProperty | cdk.IResolvable;
    interface AuthProperty {
        /**
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-serverless-api-auth.html#cfn-serverless-api-auth-adddefaultauthorizertocorspreflight
         */
        readonly addDefaultAuthorizerToCorsPreflight?: boolean | cdk.IResolvable;
        /**
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-serverless-api-auth.html#cfn-serverless-api-auth-authorizers
         */
        readonly authorizers?: any | cdk.IResolvable;
        /**
         * @see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-serverless-api-auth.html#cfn-serverless-api-auth-defaultauthorizer
         */
        readonly defaultAuthorizer?: string;

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

It should cover all supported options.

Current Behavior

only AddDefaultAuthorizerToCorsPreflight, Authorizers, and DefaultAuthorizer are supported.

Reproduction Steps

See above

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.159.1 (build c66f4e3)

Framework Version

No response

Node.js Version

20

OS

ubuntu

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

aws-cdk-libRelated to the aws-cdk-lib packagebugThis issue is a bug.effort/smallSmall work item – less than a day of effortneeds-cfnThis issue is waiting on changes to CloudFormation before it can be addressed.p2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions