簡體   English   中英

如何獲取 AWS::ApiGateway::Method 的 arn

[英]how to get arn of AWS::ApiGateway::Method

在這里我想獲取 AWS::ApiGateway::Method in AWS::Lambda::Permission "SourceArn" 屬性

這是我如何獲得 arn

當我在 SourceArn 中使用 Fn::GetAtt 獲取 lambdaAPOSTMethod 或 lambdaBPOSTMethod 時,它顯示錯誤消息說 Fn::GetAtt is not for AWS::ApiGateway::Method part

我看到我們可以做類似 SourceArn: :Join [ ",": ["arn:aws,execute-api": :Ref AWS,:Region: ,Ref AWS,:AccountId, !Ref ApiGatewayRestApi, "/*/POST /" ] ]

但我想要一些簡單的解決方案,比如 ref apigatewmethod

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": { "Environment": { "Type": "String" } },
  "Resources":
    {
      "APIGatewayRestAPI":
        {
          "Type": "AWS::ApiGateway::RestApi",
          "Properties": { "Name": { "Fn::Sub": "avllano-${Environment}" } },
        },
      "lambdaBResource":
        {
          "Type": "AWS::ApiGateway::Resource",
          "Properties":
            {
              "RestApiId": { "Ref": "APIGatewayRestAPI" },
              "ParentId":
                { "Fn::GetAtt": ["APIGatewayRestAPI", "RootResourceId"] },
              "PathPart": { "Fn::Sub": "lambdaB-${Environment}" },
            },
          "DependsOn": ["APIGatewayRestAPI"],
        },
      "lambdaBPOSTMethod":
        {
          "Type": "AWS::ApiGateway::Method",
          "Properties":
            {
              "RestApiId": { "Ref": "APIGatewayRestAPI" },
              "ResourceId": { "Ref": "lambdaBResource" },
              "HttpMethod": "POST",
              "AuthorizationType": "AWS_IAM",
              "MethodResponses": [{ "StatusCode": 200 }],
              "Integration":
                {
                  "Type": "AWS_PROXY",
                  "IntegrationResponses": [{ "StatusCode": 200 }],
                  "IntegrationHttpMethod": "POST",
                  "Uri":
                    {
                      "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:lambdaB-${Environment}/invocations",
                    },
                },
            },
          "DependsOn": ["lambdaBResource"],
        },
      "APIGatewayDeployment":
        {
          "Type": "AWS::ApiGateway::Deployment",
          "Properties":
            {
              "RestApiId": { "Ref": "APIGatewayRestAPI" },
              "StageName": { "Ref": "Environment" },
            },
          "DependsOn": ["lambdaAPOSTMethod", "lambdaBPOSTMethod"],
        },

      "lambdaAPermission":
        {
          "Type": "AWS::Lambda::Permission",
          "Properties":
            {
              "Action": "lambda:InvokeFunction",
              "FunctionName":
                {
                  "Fn::Sub": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:lambdaA-${Environment}",
                },
              "Principal": "apigateway.amazonaws.com",
              "SourceArn" : ?
            },
          "DependsOn": ["APIGatewayDeployment"],
        },
      "lambdaBPermission":
        {
          "Type": "AWS::Lambda::Permission",
          "Properties":
            {
              "Action": "lambda:InvokeFunction",
              "FunctionName":
                {
                  "Fn::Sub": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:lambdaB-${Environment}",
                },
              "Principal": "apigateway.amazonaws.com",
              "SourceArn" : ?
            },
          "DependsOn": ["APIGatewayDeployment"],
        },

    },

}

Refs 和 GetAtts 未針對 CloudFormation 資源類型一致實施。 您可以在每個文檔頁面的底部、示例之前找到它們。 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html

在這種情況下,您將不得不使用 Join 或 Sub 來構建 Arn。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM