amazon-web-services - 我们应该如何在 AWS 无服务器框架中配置 apigateway--> step function proxy?
问题描述
我们正在使用无服务器框架 ( AWS ) 创建:
ApiGateway
它step function
通过一个名为serverless-step-functions的插件连接到
这是使用插件的当前代码:serverless-step-functions
stepFunctions:
stateMachines:
fetchAndCombineDataStateMachine:
type: EXPRESS
role: ...
events:
- http:
path: /
method: POST
action: StartSyncExecution
request:
template:
application/json: |
#set( $body = $util.escapeJavaScript($input.json('$')) )
#set( $stepFunctionName = '*************************-${opt:stage}')
{
"input": "$body",
"stateMachineArn":"*************************:stateMachine:$stepFunctionName"
}
但是,在我们的 CICD 管道中,我们不能使用这个插件。所以我们必须在apigateway--> step function proxy
没有插件的情况下配置()它。
问题:
我们应该如何配置 YML 文件以允许在不使用插件的情况下Apigateway
连接到 a ?step-function
解决方案
要将 AWS API Gateway 集成配置为步进功能,您必须执行以下步骤:
- 配置Api网关资源
StepFunctionApiProxy:
Type: AWS::ApiGateway::RestApi
Properties:
Name: YourApiName
EndpointConfiguration:
Types:
- REGIONAL
Policy:
Version: '2012-10-17'
Statement:
- Effect: Deny
Principal: "*"
Action:
- execute-api:Invoke
Resource: execute-api:/*/*/*
Condition:
NotIpAddress:
aws:sourceIp:
- Whitelisted Ip address
- Whitelisted Ip address
- Effect: Allow
Principal: "*"
Action:
- execute-api:Invoke
Resource: execute-api:/*/*/*
- 配置部署资源(它会将阶段附加到您的 API 部署)
ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId:
Ref: StepFunctionApiProxy
StageName: Int
DependsOn:
- ApiGatewayMethodPost
- 配置 API 方法(请求、响应和转换模板)
ApiGatewayMethodPost:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: POST
AuthorizationType: NONE
ApiKeyRequired: false
ResourceId:
Fn::GetAtt:
- StepFunctionApiProxy
- RootResourceId
RestApiId:
Ref: StepFunctionApiProxy
Integration:
IntegrationHttpMethod: POST
Type: AWS
Credentials: [ApiGatewayRole, should have permission to run step function]
Uri:
Fn::Join:
- ''
- - 'arn:'
- Ref: AWS::Partition
- ":apigateway:"
- Ref: AWS::Region
- ":states:action/StartSyncExecution" [Here you can specify action: StartSyncExecution - wait for result]
PassthroughBehavior: WHEN_NO_TEMPLATES
RequestTemplates:
application/json: |-
#set( $body = $util.escapeJavaScript($input.json('$')) )
#set( $stepFunctionName = '[YourStepFunctionName]')
{
"input": "$body",
"stateMachineArn":"arn:aws:states:eu-west-1:[YourAmazonAccountId]:stateMachine:[stepFunctionName]"
}
application/x-www-form-urlencoded: |-
#set( $body = $util.escapeJavaScript($input.json('$')) )
#set( $stepFunctionName = '[YourStepFunctionName]')
{
"input": "$body",
"stateMachineArn":"arn:aws:states:eu-west-1:YourAmazonAccountId:stateMachine:[stepFunctionName]"
}
IntegrationResponses:
- StatusCode: 200
SelectionPattern: 200
ResponseParameters: {}
ResponseTemplates:
application/json: |
#set($inputJSON = $input.json('$'))
#set($isSuccess = !$inputJSON.toString().contains("error") && !$inputJSON.toString().contains("Exception"))
#set($xField = ($t.substring($pos1, $pos2)))
{
"payload": {
"services": $util.parseJson($inputJSON).output
},
"requestId": "$util.parseJson($util.parseJson($inputJSON).input).requestId",
"isSuccess":$isSuccess,
"xField":"$xField"
#if($inputJSON.toString().contains("error") || $inputJSON.toString().contains("Exception"))
,"error": {
"message": "$util.parseJson($inputJSON).error"
}
#end
}
- StatusCode: 400
SelectionPattern: 400
ResponseParameters: {}
ResponseTemplates: {}
MethodResponses:
- ResponseParameters: {}
ResponseModels: {}
StatusCode: 200
- ResponseParameters: {}
ResponseModels: {}
StatusCode: 400
- 配置步进功能
fetchAndCombineMapDataStateMachine:
Type: AWS::StepFunctions::StateMachine
.....
.....
.....
推荐阅读
- dart - 更改文本样式扩展列表 Flutter
- java - 创建枚举查找。单个对象的多个键
- ios - 如何正确地为隐藏在 UITableViewCell 中的 UIStackView 设置动画?
- django - django rest注册api报错:此字段为必填项
- docker - 需要重启时如何修改在Docker中运行的Payara的配置
- apache-kafka - 在集群中清理 Kafka 主题
- java - 如何使用 JDBC 以安全模式(kerberos+ssl)连接配置单元?
- r - 如何使用参数化过滤器与来自 power bi 的 r 数据进行通信
- continuous-integration - Circle CI 无法添加项目,它也不存在于工作流中
- node.js - 通过在猫鼬中填充匹配结果来查找文档