gpt4 book ai didi

amazon-web-services - 如何将API网关与SQS集成

转载 作者:行者123 更新时间:2023-12-04 01:46:23 28 4
gpt4 key购买 nike

就像标题一样。我尝试使用云形成将 API 网关方法与 SQS 集成。我缺少的是 SQS 的正确 URI。如果你们中有人已经这样做了,那么 URI 应该是什么样子的?

我想出了类似的方法,但不知道将 SQS ARN 放在哪里

"arn:aws:apigateway:${AWS::Region}:sqs:action/SendMessage"

这是该方法的完整配置:

PostMethod:
Type: "AWS::ApiGateway::Method"
Properties:
ApiKeyRequired: "true"
HttpMethod: "POST"
ResourceId: !Ref "SomeResource"
RestApiId: !Ref "SomeRestApi"
Integration:
IntegrationHttpMethod: "POST"
IntegrationResponses:
- StatusCode: 200
Type: "AWS"
Uri: "arn:aws:apigateway:${AWS::Region}:sqs:action/SendMessage"

如果您与 lambda 函数集成,这里是 URI 的示例:

arn:aws:apigateway:us-west-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-west-2:123412341234:function:function_name/invocations
-

最佳答案

回答我自己的问题。以下是将 SQS 作为服务代理集成到 API 网关中的方法:

PostMethod:
Type: "AWS::ApiGateway::Method"
Properties:
AuthorizationType: "NONE"
ApiKeyRequired: "true"
HttpMethod: "POST"
ResourceId: !Ref "SomeResource"
RestApiId: !Ref "RestApi"
MethodResponses:
- StatusCode: 200
Integration:
Credentials: !GetAtt "RestApiRole.Arn"
IntegrationHttpMethod: "POST"
IntegrationResponses:
- StatusCode: 200
Type: "AWS"
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:sqs:action/SendMessage"
RequestParameters:
integration.request.querystring.QueueUrl: !Sub "'${SomeQueue}'"
integration.request.querystring.MessageBody: "method.request.body"

我终于在各种文档中找到了我的问题的所有答案。我猜是 RTFM。

编辑:

这里是 RestApiRole 的代码:

RestApiRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "sts:AssumeRole"
Principal:
Service:
- "apigateway.amazonaws.com"
Effect: "Allow"
Policies:
- PolicyName: "InvokeLambda"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "lambda:InvokeFunction"
Resource: !GetAtt "LambdaFunction.Arn"
Effect: "Allow"

关于amazon-web-services - 如何将API网关与SQS集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41097441/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com