在指定了 AWS::Serverless::Function 的情况下生成的 CloudFormation 资源 - AWS Serverless Application Model

在指定了 AWS::Serverless::Function 的情况下生成的 CloudFormation 资源

如果指定了 AWS::Serverless::Function,AWS Serverless Application Model (AWS SAM) 总是创建 AWS::Lambda::Function 基本 CloudFormation 资源。

AWS::Lambda::Function

LogicalId: <function‑LogicalId>

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

除了这种 CloudFormation 资源外,如果指定了 AWS::Serverless::Function,AWS SAM 还会生成适用于以下场景的 CloudFormation 资源。

核心函数属性

以下场景基于核心功能属性生成 CloudFormation 资源:

未指定 Role 属性

如果指定 AWS::Serverless::FunctionRole 属性,AWS SAM 会生成 AWS::IAM::Role CloudFormation 资源。

AWS::IAM::Role

LogicalId: <function‑LogicalId>Role

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

指定了 AutoPublishAlias 属性

如果指定了 AWS::Serverless::FunctionAutoPublishAlias 属性,AWS SAM 会生成以下 CloudFormation 资源:AWS::Lambda::AliasAWS::Lambda::Version

AWS::Lambda::Alias

LogicalId: <function‑LogicalId>Alias<alias‑name>

<alias‑name>AutoPublishAlias 将被设置为的字符串。例如,如果将 AutoPublishAlias 设置为 live,则 LogicalId 是:MyFunctionAliaslive

可引用属性:<function‑LogicalId>.Alias

AWS::Lambda::Version

LogicalId: <function‑LogicalId>Version<sha>

<sha> 是在创建堆栈时生成的唯一哈希值。例如,MyFunctionVersion926eeb5ff1

可引用属性:<function‑LogicalId>.Version

有关 AutoPublishAlias 属性的其他信息,请参阅 AWS::Serverless::Function 的“属性”部分

指定了 DeploymentPreference 属性

如果指定了 AWS::Serverless::FunctionDeploymentPreference 属性,AWS SAM 会生成以下 CloudFormation 资源:AWS::CodeDeploy::ApplicationAWS::CodeDeploy::DeploymentGroup。此外,如果指定 DeploymentPreference 对象的 Role 属性,AWS SAM 还会生成 AWS::IAM::Role CloudFormation 资源。

AWS::CodeDeploy::Application

LogicalId: ServerlessDeploymentApplication

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

AWS::CodeDeploy::DeploymentGroup

LogicalId: <function‑LogicalId>DeploymentGroup

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

AWS::IAM::Role

LogicalId: CodeDeployServiceRole

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

已指定 FunctionUrlConfig 属性

当指定 FunctionUrlConfig 属性时,AWS SAM 会根据 AuthType 生成不同的 CloudFormation 资源。

当指定 AuthType: NONE 时,AWS SAM 会生成以下 CloudFormation 资源:

AWS::Lambda::Permission(调用访问权限)

LogicalId: <function‑LogicalId>URLInvokeAllowPublicAccess

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

AWS::Lambda::Permission(公有访问权限)

LogicalId: <function‑LogicalId>UrlPublicPermissions

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

AWS::Lambda::Url

LogicalId: <function‑LogicalId>Url

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

当指定 AuthType: AWS_IAM 时,仅生成 AWS SAM:

AWS::Lambda::Url

LogicalId: <function‑LogicalId>Url

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

有关 FunctionUrlConfig 属性的更多信息,请参阅 FunctionUrlConfig

事件源

以下场景基于事件源生成 CloudFormation 资源:

指定了 Api 事件源

如果 AWS::Serverless::FunctionEvent 属性设置为 Api,但指定 RestApiId 属性,AWS SAM 会生成 AWS::ApiGateway::RestApi CloudFormation 资源。

AWS::ApiGateway::RestApi

LogicalId: ServerlessRestApi

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

指定了 HttpApi 事件源

如果 AWS::Serverless::FunctionEvent 属性设置为 HttpApi,但指定 ApiId 属性,AWS SAM 会生成 AWS::ApiGatewayV2::Api CloudFormation 资源。

AWS::ApiGatewayV2::Api

LogicalId: ServerlessHttpApi

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

指定了流式事件源

如果 AWS::Serverless::FunctionEvent 属性设置为流式处理类型之一,AWS SAM 会生成 AWS::Lambda::EventSourceMapping CloudFormation 资源。这适用于以下类型:DynamoDBKinesisMQMSKSQS

AWS::Lambda::EventSourceMapping

LogicalId: <function‑LogicalId><event‑LogicalId>

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

指定了事件桥(或事件总线)事件源

如果 AWS::Serverless::FunctionEvent 属性设置为事件桥(或事件总线)类型之一,AWS SAM 会生成 AWS::Events::Rule CloudFormation 资源。这适用于以下类型:EventBridgeRuleScheduleCloudWatchEvents

AWS::Events::Rule

LogicalId: <function‑LogicalId><event‑LogicalId>

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

指定了 IotRule 事件源

如果 AWS::Serverless::FunctionEvent 属性设置为 IoTRule,AWS SAM 会生成 AWS::IoT::TopicRule CloudFormation 资源。

AWS::IoT::TopicRule

LogicalId: <function‑LogicalId><event‑LogicalId>

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

事件配置

以下场景基于事件配置生成 CloudFormation 资源:

为 Amazon SNS 事件指定了 OnSuccess(或 OnFailure)属性

如果指定了 DestinationConfig 属性的 OnSuccess(或 OnFailure)属性或指定了 AWS::Serverless::FunctionEventInvokeConfig 属性,且目的地类型为 SNS,但指定目的地 ARN,AWS SAM 会生成以下 CloudFormation 资源:AWS::Lambda::EventInvokeConfigAWS::SNS::Topic

AWS::Lambda::EventInvokeConfig

LogicalId: <function‑LogicalId>EventInvokeConfig

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

AWS::SNS::Topic

LogicalId: <function‑LogicalId>OnSuccessTopic(或 <function‑LogicalId>OnFailureTopic

可引用属性:<function‑LogicalId>.DestinationTopic

如果为 Amazon SNS 事件指定了 OnSuccessOnFailure,为了区分生成的资源,必须使用 LogicalId

为 Amazon SQS 事件指定了 OnSuccess(或 OnFailure)属性

如果指定了 DestinationConfig 属性的 OnSuccess(或 OnFailure)属性或指定了 AWS::Serverless::FunctionEventInvokeConfig 属性,且目的地类型为 SQS,但指定目的地 ARN,AWS SAM 会生成以下 CloudFormation 资源:AWS::Lambda::EventInvokeConfigAWS::SQS::Queue

AWS::Lambda::EventInvokeConfig

LogicalId: <function‑LogicalId>EventInvokeConfig

可引用属性:不适用(必须使用 LogicalId 才能引用这种 CloudFormation 资源)

AWS::SQS::Queue

LogicalId: <function‑LogicalId>OnSuccessQueue(或 <function‑LogicalId>OnFailureQueue

可引用属性:<function‑LogicalId>.DestinationQueue

如果为 Amazon SQS 事件指定了 OnSuccessOnFailure,为了区分生成的资源,必须使用 LogicalId