AWS API Gateway与AWS Lambda代理集成构建REST API

article/2025/11/1 14:12:51

项目地址

https://github.com/JessicaWin/aws

  • lambda分支为自动创建API Gateway REST API资源的部署方式
  • apigateway分支为自定义API Gateway REST API资源的部署方式

创建Lambda Handler

创建父模块

使用idea创建一个maven工程: File->New->Project

在左侧菜单栏中选择Maven,点击Next:

输入groupId和artifactId,点击Next:

最终点击finish创建完成.

修改父模块的pom文件,引入aws lambda, log, json相关的jar包管理:

    <properties><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.source>1.8</maven.compiler.source></properties><dependencyManagement><dependencies><dependency><groupId>com.amazonaws</groupId><artifactId>aws-lambda-java-core</artifactId><version>1.2.0</version></dependency><dependency><groupId>com.amazonaws</groupId><artifactId>aws-lambda-java-events</artifactId><version>3.1.0</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.26</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.26</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.11.0</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.11.0</version></dependency></dependencies></dependencyManagement>

创建子模块

首先选中aws project,然后Intellij -> File -> New Module,在弹出的对话框中选择Maven, 使用默认配置,然后Next进入下一步配置。

配置项目的group和artifact等信息(可以根据自己需要进行配置),点击Next进入下一步配置。

  • Grouop: com.jessica
  • Artifact:aws-lambda

设置module name为aws-lambda,点击finish完成创建.

修改子模块的pom文件,引入aws lambda, log, json相关的jar包:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>aws</artifactId><groupId>org.example</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>aws-lambda</artifactId><properties><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.source>1.8</maven.compiler.source></properties><dependencies><dependency><groupId>com.amazonaws</groupId><artifactId>aws-lambda-java-core</artifactId></dependency><dependency><groupId>com.amazonaws</groupId><artifactId>aws-lambda-java-events</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-shade-plugin</artifactId><configuration><createDependencyReducedPom>false</createDependencyReducedPom></configuration><executions><execution><phase>package</phase><goals><goal>shade</goal></goals><configuration><!-- remove version from package name --><finalName>${project.artifactId}</finalName><createDependencyReducedPom>false</createDependencyReducedPom></configuration></execution></executions></plugin></plugins></build>
</project>

在子模块的src/main/resources目录下添加日志配置文件log4j.properties

log4j.rootLogger=DEBUG,system.out
log4j.appender.system.out=org.apache.log4j.ConsoleAppender
log4j.appender.system.out.layout=org.apache.log4j.PatternLayout
log4j.appender.system.out.layout.ConversionPattern=[%t] %-5p %c %x - %m%n

在子模块中创建lambda函数的request和response

GreetingRequestVo.java

package com.jessica.aws.lambda;import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GreetingRequestVo {private String name;private String time;private String city;private String day;
}

GreetingResponseVo.java

package com.jessica.aws.lambda;import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GreetingResponseVo {private String greeting;
}

在子模块中创建一个Lambda Handler

LambdaProxyHandler.java

package com.jessica.aws.lambda;import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;public class LambdaProxyHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {private static final Logger LOGGER = LoggerFactory.getLogger(LambdaProxyHandler.class);private static final ObjectMapper mapper = new ObjectMapper();@Overridepublic APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {GreetingRequestVo greetingRequestVo = null;try {LOGGER.info("api gateway event is: " + event);String requestBody = event.getBody();LOGGER.info("api requestBody: " + event);greetingRequestVo = mapper.readValue(requestBody, GreetingRequestVo.class);String greeting = String.format("Good %s, %s of %s.[ Happy %s!]",greetingRequestVo.getTime(), greetingRequestVo.getName(), greetingRequestVo.getCity(), greetingRequestVo.getDay());LOGGER.info("name is " + greetingRequestVo.getName());GreetingResponseVo response = GreetingResponseVo.builder().greeting(greeting).build();String responseBody = mapper.writeValueAsString(response);APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();responseEvent.setBody(responseBody);responseEvent.setStatusCode(200);return responseEvent;} catch (JsonProcessingException e) {APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent();responseEvent.setStatusCode(500);return responseEvent;}}
}

创建config.yml文件

在aws-lambda子模块中创建config.yml文件,该文件主要用于配置当前service的通用参数设置,同时用于作为lambda函数的环境变量

# Variant of each developer
variant: jessicastage: develop# The region you will deploy your lambda to
region: ap-southeast-1# The bucket your upload your lambda resource(Including jar) to
deploymentBucket: ${self:provider.stage}-social-network-deploy# AWS Account ID
ACCOUNT_ID:Ref: 'AWS::AccountId'versionFunctions: false

创建serverless.yml部署文件

serverless.yml文件用于创建lambda函数, apigateway的相关资源(AWS::ApiGateway::RestApi, AWS::ApiGateway::Resource,  AWS::ApiGateway::Method),lambda函数的调用条件,权限等.

自动创建API Gateway REST API资源

在serverless.yml中配置lambda函数,在函数部署时会自动为该函数创建LogGroup,如果指定了http类型的event,则在部署时会自动为该函数创建event对应的apigateway的相关资源(AWS::ApiGateway::RestApi, AWS::ApiGateway::Resource,  AWS::ApiGateway::Method),以及apigateway event调用lambda函数的权限.

部署文件

service: aws-lambda
frameworkVersion: ">=1.2.0 <2.0.0"
plugins:- serverless-pseudo-parameterscustom:configFile: ${file(config.yml)}provider:name: awsstage: ${self:custom.configFile.stage}variant: ${self:custom.configFile.variant}runtime: java8region: ${self:custom.configFile.region}timeout: 30 # The default is 6 seconds. Note: API Gateway current maximum is 30 secondsmemorySize: 1024 # Overwrite the default memory size. Default is 1024. Increase by 64.deploymentBucket: ${self:custom.configFile.deploymentBucket}environment: ${file(config.yml)}stackName: ${self:provider.stage}-${self:provider.variant}-${self:service}versionFunctions: ${self:custom.configFile.versionFunctions}package:artifact: target/aws-lambda.jarfunctions:LambdaProxyHandler:# name must have length less than or equal to 64name: ${self:provider.stage}-${self:provider.variant}-LambdaProxyHandlerhandler: com.jessica.aws.lambda.LambdaProxyHandlerrole: arn:aws:iam::#{AWS::AccountId}:role/AdminRoleevents:- http:path: /hellomethod: POST

部署

$ sls deploy -v
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (4.7 MB)...
Serverless: Validating template...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - develop-jessica-aws-lambda
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - LambdaProxyHandlerLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - LambdaProxyHandlerLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - LambdaProxyHandlerLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceHello
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - LambdaProxyHandlerLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceHello
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceHello
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - LambdaProxyHandlerLambdaFunction
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - LambdaProxyHandlerLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - LambdaProxyHandlerLambdaPermissionApiGateway
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodHelloPost
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - LambdaProxyHandlerLambdaPermissionApiGateway
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodHelloPost
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodHelloPost
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Deployment - ApiGatewayDeployment1592312567124
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Deployment - ApiGatewayDeployment1592312567124
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Deployment - ApiGatewayDeployment1592312567124
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Permission - LambdaProxyHandlerLambdaPermissionApiGateway
CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - develop-jessica-aws-lambda
Serverless: Stack create finished...
Service Information
service: aws-lambda
stage: develop
region: ap-southeast-1
stack: develop-jessica-aws-lambda
api keys:None
endpoints:POST - https://********.execute-api.ap-southeast-1.amazonaws.com/develop/hello
functions:LambdaProxyHandler: aws-lambda-develop-LambdaProxyHandler
layers:NoneStack Outputs
ServiceEndpoint: https://********.execute-api.ap-southeast-1.amazonaws.com/develop
ServerlessDeploymentBucketName: develop-social-network-deploy

通过log可以看出,lambda函数部署时一共创建了7个资源:

  • AWS::ApiGateway::RestApi
  • AWS::Logs::LogGroup
  • AWS::ApiGateway::Resource
  • AWS::Lambda::Function
  • AWS::ApiGateway::Method
  • AWS::Lambda::Permission
  • AWS::ApiGateway::Deployment

测试

打开apigateway的页面:https://ap-southeast-1.console.aws.amazon.com/apigateway/main/apis?region=ap-southeast-1

在api列表中可以找到刚部署的名为 develop-aws-lambda的api:

打开api页面,可以看到api相关信息,点击/hello下面的POST方法,可以看到hello api的完整信息:

击点TEST可以进行测试,测试时输入如下的request body:

{
    "name":"jesscia",
    "time":"21:00",
    "city":"shanghai",
    "day":"2020/06/10"
}

自定义API Gateway REST API资源

在aws-lambda的serverless.yml中只配置lambda函数,不指定event.

在aws-lambda的根目录下创建一个api目录,并在其中创建一个serverless.yml用于对apigateway的相关资源(AWS::ApiGateway::RestApi, AWS::ApiGateway::Resource,  AWS::ApiGateway::Method)以及调用lambda函数的权限进行配置.

lambda配置文件aws-lambda/serverless.yml

service: aws-apigateway-lambda
frameworkVersion: ">=1.2.0 <2.0.0"
plugins:- serverless-pseudo-parameterscustom:configFile: ${file(config.yml)}provider:name: awsstage: ${self:custom.configFile.stage}variant: ${self:custom.configFile.variant}runtime: java8region: ${self:custom.configFile.region}timeout: 30 # The default is 6 seconds. Note: API Gateway current maximum is 30 secondsmemorySize: 1024 # Overwrite the default memory size. Default is 1024. Increase by 64.deploymentBucket: ${self:custom.configFile.deploymentBucket}environment: ${file(config.yml)}stackName: ${self:provider.stage}-${self:provider.variant}-${self:service}versionFunctions: ${self:custom.configFile.versionFunctions}package:artifact: target/aws-lambda.jarfunctions:LambdaProxyHelloHandler:# name must have length less than or equal to 64name: ${self:provider.stage}-${self:provider.variant}-LambdaProxyHelloHandlerhandler: com.jessica.aws.lambda.LambdaProxyHandlerrole: arn:aws:iam::#{AWS::AccountId}:role/AdminRoleresources:Outputs:LambdaProxyHelloHandlerArn:Description: The ARN for the hello functionValue:# the first param must be:  string.contact(functionId, LambdaFunction)Fn::GetAtt:- LambdaProxyHelloHandlerLambdaFunction- ArnExport:Name: ${self:provider.stage}-${self:provider.variant}-LambdaProxyHelloHandlerArn

apigateway配置文件aws-lambda/api/serverless.yml

service: aws-apigateway-api
frameworkVersion: ">=1.2.0 <2.0.0"
plugins:- serverless-pseudo-parameterscustom:configFile: ${file(../config.yml)}provider:name: awsstage: ${self:custom.configFile.stage}variant: ${self:custom.configFile.variant}region: ${self:custom.configFile.region}deploymentBucket: ${self:custom.configFile.deploymentBucket}stackName: ${self:provider.stage}-${self:provider.variant}-${self:service}helloFunctionArn:Fn::ImportValue: ${self:provider.stage}-${self:provider.variant}-LambdaProxyHelloHandlerArnresources:Resources:# api gateway rootApiGatewayRestApi:Type: AWS::ApiGateway::RestApiProperties:Name: ${self:provider.stage}_${self:provider.variant}_ApiGatewayRootRestApiEndpointConfiguration:Types:- REGIONAL# /helloApiGatewayResourceHello:Type: AWS::ApiGateway::ResourceProperties:RestApiId:Ref: ApiGatewayRestApiParentId:Fn::GetAtt:- ApiGatewayRestApi- RootResourceIdPathPart: helloRootMethod:Type: AWS::ApiGateway::MethodProperties:ResourceId:Fn::GetAtt:- ApiGatewayRestApi- RootResourceIdRestApiId:Ref: ApiGatewayRestApiHttpMethod: GETAuthorizationType: NONEMethodResponses:- StatusCode: 302ResponseParameters:method.response.header.Location: trueIntegration:Type: MOCKRequestTemplates:'application/json': '{"statusCode":200}'IntegrationResponses:- StatusCode: 302ApiGatewayMethodHelloPost:Type: AWS::ApiGateway::MethodProperties:HttpMethod: POSTRequestParameters: {}ResourceId:Ref: ApiGatewayResourceHelloRestApiId:Ref: ApiGatewayRestApiApiKeyRequired: falseAuthorizationType: NONEIntegration:IntegrationHttpMethod: POSTType: AWS_PROXYUri:# Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joinedFn::Join:- ''- - 'arn:'- Ref: 'AWS::Partition'- ':apigateway:'- Ref: 'AWS::Region'- ':lambda:path/2015-03-31/functions/'- ${self:provider.helloFunctionArn}- /invocationsMethodResponses: []LambdaProxyHandlerLambdaPermissionApiGateway:Type: AWS::Lambda::PermissionProperties:FunctionName: ${self:provider.helloFunctionArn}Action: lambda:InvokeFunctionPrincipal: apigateway.amazonaws.comSourceArn:Fn::Join:- ''- - 'arn:'- Ref: 'AWS::Partition'- ':execute-api:'- Ref: 'AWS::Region'- ':'- Ref: 'AWS::AccountId'- ':'- Ref: ApiGatewayRestApi- /*/*Outputs:ApiGatewayRestApiId:Value:Ref: ApiGatewayRestApiExport:Name: ${self:provider.stage}-${self:provider.variant}-ApiGatewayRootRestApiIdApiGatewayRootResourceId:Value:Fn::GetAtt:- ApiGatewayRestApi- RootResourceIdExport:Name: ${self:provider.stage}-${self:provider.variant}-ApiGatewayRootResourceIdApiGatewayResourceIdHello:Value:Ref: ApiGatewayResourceHelloExport:Name: ${self:provider.stage}-${self:provider.variant}-ApiGatewayResourceId-helloServiceEndpoint:Description: 'URL of the service endpoint'Value:Fn::Join:- ''- - 'https://'- Ref: ApiGatewayRestApi- '.execute-api.'- Ref: 'AWS::Region'- '.'- Ref: 'AWS::URLSuffix'- '/'- ${self:provider.stage}

部署lambda函数

$ $ sls deploy -v
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (4.7 MB)...
Serverless: Validating template...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - develop-jessica-aws-apigateway-lambda
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - LambdaProxyHelloHandlerLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - LambdaProxyHelloHandlerLogGroup
CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - LambdaProxyHelloHandlerLogGroup
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - LambdaProxyHelloHandlerLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - LambdaProxyHelloHandlerLambdaFunction
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - LambdaProxyHelloHandlerLambdaFunction
CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - develop-jessica-aws-apigateway-lambda
Serverless: Stack create finished...
Service Information
service: aws-apigateway-lambda
stage: develop
region: ap-southeast-1
stack: develop-jessica-aws-apigateway-lambda
api keys:None
endpoints:None
functions:LambdaProxyHelloHandler: aws-apigateway-lambda-develop-LambdaProxyHelloHandler
layers:NoneStack Outputs
LambdaProxyHelloHandlerArn: arn:aws:lambda:ap-southeast-1:*********:function:develop-jessica-LambdaProxyHelloHandler
ServerlessDeploymentBucketName: develop-social-network-deploy

通过log可以看出,lambda函数部署时一共创建了2个资源:

  • AWS::Logs::LogGroup
  • AWS::Lambda::Function

部署apigateway

$  sls deploy -v
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Validating template...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - develop-jessica-aws-apigateway-api
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::RestApi - ApiGatewayRestApi
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceHello
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - RootMethod
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - LambdaProxyHandlerLambdaPermissionApiGateway
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Resource - ApiGatewayResourceHello
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - RootMethod
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - LambdaProxyHandlerLambdaPermissionApiGateway
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Resource - ApiGatewayResourceHello
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Method - RootMethod
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodHelloPost
CloudFormation - CREATE_IN_PROGRESS - AWS::ApiGateway::Method - ApiGatewayMethodHelloPost
CloudFormation - CREATE_COMPLETE - AWS::ApiGateway::Method - ApiGatewayMethodHelloPost
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Permission - LambdaProxyHandlerLambdaPermissionApiGateway
CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - develop-jessica-aws-apigateway-api
Serverless: Stack create finished...
Service Information
service: aws-apigateway-api
stage: develop
region: ap-southeast-1
stack: develop-jessica-aws-apigateway-api
api keys:None
endpoints:
functions:None
layers:NoneStack Outputs
ApiGatewayRestApiId: ******
ApiGatewayRootResourceId: ******
ApiGatewayResourceIdHello: ******
ServiceEndpoint: https://******.execute-api.ap-southeast-1.amazonaws.com/develop
ServerlessDeploymentBucketName: develop-social-network-deploy

通过log可以看出,lambda函数部署时一共创建了5个资源:

  • AWS::ApiGateway::RestApi
  • AWS::ApiGateway::Resource
  • AWS::ApiGateway::Method - RootMethod
  • AWS::ApiGateway::Method - ApiGatewayMethodHelloPost
  • AWS::Lambda::Permission

测试

打开apigateway的页面:https://ap-southeast-1.console.aws.amazon.com/apigateway/main/apis?region=ap-southeast-1

在api列表中可以找到刚部署的名为 develop_jessica_ApiGatewayRootRestApi的api:

打开api页面,可以看到api相关信息,点击/hello下面的POST方法,可以看到hello api的完整信息:

 

点击 TEST可以对api进行测试,输入图示的request body进行测试,可以得到正确的返回结果:

{
    "name":"jesscia",
    "time":"21:00",
    "city":"shanghai",
    "day":"2020/06/10"
}

 

参考

https://www.serverless.com/framework/docs/providers/aws/guide/functions/

https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-integration

https://www.gorillastack.com/news/splitting-your-serverless-framework-api-on-aws/

https://docs.aws.amazon.com/zh_cn/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html

https://docs.aws.amazon.com/zh_cn/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

https://docs.aws.amazon.com/zh_cn/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html


http://chatgpt.dhexx.cn/article/i7yDf8qY.shtml

相关文章

基于 Amazon API Gateway 的跨账号跨网络的私有 API 集成

一、背景介绍 本文主要讨论的问题是在使用 Amazon API Gateway&#xff0c;通过 Private Integration、Private API 来完成私有网络环境下的跨账号或跨网络的 API 集成。API 管理平台会被设计在单独的账号中(亚马逊云科技提供的是多租户的环境)&#xff0c;因为客观上不同业务…

AWS Lambda 搭配 Amazon API Gateway (HTTP API)

AWS Lambda 搭配 Amazon API Gateway (HTTP API) AWS Lambda 是一种无伺服器、事件推动的运算服务&#xff0c;而 Amazon API Gateway 可以让开发人员轻松地建立、发布、维护、监控和保护任何规模的 API&#xff0c;使用 API Gateway 可以建立 RESTful API 和 WebSocket API&a…

AWS API gateway api CORS错误处理方法

我们开发了一个 AWS lambda 函数&#xff0c;然后我们使用 AWS API gateway服务将它上线。 我们已经测试 API 并验证它是否按照我们的预期工作&#xff0c;看起来真的很棒。 现在我们准备好将 API 端点发送到我们的前端并从网站调用它。 一旦我们这样做了&#xff0c;我们就…

API管理的正确姿势--API Gateway

转载本文需注明出处&#xff1a;微信公众号EAWorld&#xff0c;违者必究。 数字化生态&#xff0c;以创新客户体验为核心&#xff0c;所有我们身边能感知到的变化都来自于渐近的创新。这些创新需要试错&#xff0c;需要不断的升级&#xff0c;并且创新往往与我们熟知的功能分离…

AWS——API Gateway

文章目录 APIHTTP API构建操作*路由*授权集成部署——阶段 REST API构建操作*资源*阶段授权方 自定义域名ACM证书&#xff1f;API 映射 VPC链接REST APIHTTP API子网&#xff1f;安全组&#xff1f; API 选择创建API的类型时&#xff0c;创建的是对公访问的gateway方式&#x…

使用AWS的API Gateway实现websocket

问题 最近业务上面需要使用到WebSocket长连接来解决某些业务场景。 一图胜千言 注意&#xff1a;这里承担WebSocket服务器的是AWS API Gateway&#xff1b;后面的EC2业务服务&#xff0c;其实都是REST接口服务。 这里主要关注API Gateway和REST业务服务怎么实现API Gateway要…

使用API Gateway

使用API Gateway 转自&#xff1a;http://www.open-open.com/lib/view/open1436089902667.html 它讨论了采用微服务的优点和缺点&#xff0c;除了一些复杂的微服务&#xff0c;这种模式还是复杂应用的理想选择。 当你决定将应用作为一组微服务时&#xff0c;需要决定应用客户端…

aws api gateway 创建

在这个章节中&#xff0c;你将创建一个无服务器API。无服务器API让你专注于你的应用&#xff0c;而不是花时间配置和管理服务器。 首先&#xff0c;你使用AWS Lambda控制台创建一个Lambda函数。接下来&#xff0c;你使用API网关控制台创建一个HTTP API。然后&#xff0c;你调用…

微服务实践(二):使用API Gateway

【编者的话】本系列的第一篇介绍了微服务架构模式。它讨论了采用微服务的优点和缺点&#xff0c;除了一些复杂的微服务&#xff0c;这种模式还是复杂应用的理想选择。 点击这里获取云原生干货 当你决定将应用作为一组微服务时&#xff0c;需要决定应用客户端如何与微服务交互。…

AWS API GATEWAY的使用

AWS API GATEWAY 文章目录 1、Create Vpc endpoint2、Target Groups与Load Balancer2.1、Create target type为Instances的Target Groups2.2、Create Application Load Balancer2.3、Create target type为Application Load Balancer的Target Groups2.4、Create Network Load Ba…

API Gateway简介

Amazon API Gateway可以让开发人员创建、发布、维护、监控和保护任何规模的API。你可以创建能够访问 AWS、其他 Web 服务以及存储在 AWS 云中的数据的API。 API Gateway没有最低使用成本&#xff0c;我们用多少服务内容就花费多少。 比如在最新的A Cloud Guru的serverless 会…

API Gateway介绍

使用微服务架构开发应用后&#xff0c;每个微服务都将拥有自己的API&#xff0c;设计应用外部API的任务因客户端的多样性而变得更具有挑战性。不同客户端通常需要不同的数据。通常基于PC浏览器的用户界面显示的信息要远多于移动设备的用户界面。此外&#xff0c;不同的客户端通…

API 网关 ( API gateway )

前言 在 IOT &#xff08; 物联网 &#xff09;中&#xff0c;当我们的一些设备。例如&#xff08; 监控、传感器等 &#xff09;需要将收集到的数据和信息进行汇总时&#xff0c;我们就需要一个 API 网关来接收从千百个终端发出的请求&#xff0c;它实现对外统一接口&#xf…

【学习笔记】API网关(GateWay)

项目场景 提示&#xff1a;这里可以添加本文要记录的大概内容&#xff1a; 微服务将一个大型工程转成了诺干个微服务&#xff0c;每个微服务都是一个独立的项目因此每一个项目都有不同的端口&#xff0c;那我们怎样在前端发送请求的时候能精确的发送到我们所需要的服务里。 提…

APIGateway简介

综合了一下网上的APIGateway教学&#xff0c;总结了一下&#xff08;所有图片来源于网络&#xff09;: 目录 1.什么是APIGateway 2.APIGateway的作用 3.APIGateway的重要功能 1.什么是APIGateway APIGateway 即API网关是一个服务器&#xff0c;所有请求首先会经过这个网关…

java 中 ajax 的学习

1、原生 ajax 实现 首先在 web 工程下创建一个 .jsp 文件&#xff0c;用来与前台 ajax 进行数据传递 在创建的 .jsp 文件中->引入 jquery-1.8.3.min.js 文件&#xff08;可直接粘贴至 web 目录下&#xff0c;也可新建一个 js 文件夹&#xff0c;然后粘贴进去&#xff09; …

Java要学到什么程度?

在刚开始学习Java的同学都关心这么一个问题&#xff1a;到底把Java学到何种程度才能找到第一份工作呢&#xff1f;大部分人的目标是一致的&#xff0c;也比较现实&#xff0c;都是为了能找到像别人高薪的工作。那到底一个Java初学者要学多少Java知识&#xff0c;才能找到第一份…

学了python再学java要多久,有java基础学python要多久

python的学习难度如何&#xff0c;已经掌握java的话&#xff0c;想学习python批量处理文件的脚本&#xff0c;大概需要多长时间&#xff1f; 谷歌人工智能写作项目&#xff1a;小发猫 学会python大概要多久&#xff1f; 系统的学习&#xff0c;大概6个月就够了vue哪个版本支持…

自学Java开发一般需要多久?

自学Java开发一般需要多久&#xff1f;相信有很多想转行或者想学习Java的人都会关注这个问题&#xff01;那我们今天就来说一下这个问题&#xff0c;具体需要多久呢&#xff1f;这个时间因人而异&#xff0c;毕竟每个人的学习能力和效率都是不同的&#xff01; 打个比方&#x…

Java后端学习路线分享

Java后端学习路线&#xff1f;最近有些网友问我如何学习 Java 后端&#xff0c;还有些是想从别的方向想转过来&#xff0c;但都不太了解 Java 后端究竟需要学什么&#xff0c;究竟要从哪里学起&#xff0c;哪些是主流的 Java 后端技术等等&#xff0c;导致想学&#xff0c;但又…