本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ResourceReference
資源AWS::Serverless::Connector類型使用的資源參考。
注意
對於相同範本中的資源,請提供 Id。對於不在相同範本中的資源,請使用其他屬性的組合。如需詳細資訊,請參閱AWS SAM 連接器參考。
語法
若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體,請使用下列語法。
YAML
Arn:StringId:StringName:StringQualifier:StringQueueUrl:StringResourceId:StringRoleName:StringType:String
屬性
-
Arn -
資源的 ARN。
類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
-
Id -
相同範本中資源的邏輯 ID。
注意
指定
Id時,如果連接器產生 AWS Identity and Access Management (IAM) 政策,則會從資源 推斷與這些政策相關聯的 IAM 角色Id。Id未指定 時,請提供 接頭RoleName的資源,以將產生的 IAM 政策連接至 IAM 角色。類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
-
Name -
資源的名稱。
類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
-
Qualifier -
資源的限定詞縮小其範圍。 會
Qualifier取代資源限制條件 ARN 結尾*的值。如需範例,請參閱「API Gateway 叫用 Lambda 函數」。注意
限定詞定義會因資源類型而異。如需支援的來源和目的地資源類型清單,請參閱AWS SAM 連接器參考。
類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
-
QueueUrl -
Amazon SQS 佇列 URL。此屬性僅適用於 Amazon SQS 資源。
類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
-
ResourceId -
資源的 ID。例如,API Gateway API ID。
類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
-
RoleName -
與資源相關聯的角色名稱。
注意
指定
Id時,如果連接器產生 IAM 政策,則會從資源 推斷與這些政策相關聯的 IAM 角色Id。Id未指定 時,請提供 接頭RoleName的資源,以將產生的 IAM 政策連接至 IAM 角色。類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
-
Type -
資源的 CloudFormation 類型。如需詳細資訊,請前往AWS 資源和屬性類型參考。
類型:字串
必要:有條件
CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。
範例
API Gateway 叫用 Lambda 函數
下列範例使用 AWS::Serverless::Connector 資源來允許 Amazon API Gateway 叫用 AWS Lambda 函數。
YAML
Transform: AWS::Serverless-2016-10-31 Resources: MyRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Statement: - Effect: Allow Action: sts:AssumeRole Principal: Service: lambda.amazonaws.com ManagedPolicyArns: - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole MyFunction: Type: AWS::Lambda::Function Properties: Role: !GetAtt MyRole.Arn Runtime: nodejs16.x Handler: index.handler Code: ZipFile: | exports.handler = async (event) => { return { statusCode: 200, body: JSON.stringify({ "message": "It works!" }), }; }; MyApi: Type: AWS::ApiGatewayV2::Api Properties: Name: MyApi ProtocolType: HTTP MyStage: Type: AWS::ApiGatewayV2::Stage Properties: ApiId: !Ref MyApi StageName: prod AutoDeploy: True MyIntegration: Type: AWS::ApiGatewayV2::Integration Properties: ApiId: !Ref MyApi IntegrationType: AWS_PROXY IntegrationUri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations IntegrationMethod: POST PayloadFormatVersion: "2.0" MyRoute: Type: AWS::ApiGatewayV2::Route Properties: ApiId: !Ref MyApi RouteKey: GET /hello Target: !Sub integrations/${MyIntegration} MyConnector: Type: AWS::Serverless::Connector Properties: Source: # Use 'Id' when resource is in the same template Type: AWS::ApiGatewayV2::Api ResourceId: !Ref MyApi Qualifier: prod/GET/hello # Or "*" to allow all routes Destination: # Use 'Id' when resource is in the same template Type: AWS::Lambda::Function Arn: !GetAtt MyFunction.Arn Permissions: - Write Outputs: Endpoint: Value: !Sub https://${MyApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/prod/hello