Skip to content

Commit f6f62ea

Browse files
markusguldenKevinGilmore
authored andcommitted
BAEL-1727 (eugenp#4575)
* Moved Lambda examples to separate module Implementation of API Gateway example * Format fixes * Format fixes * Minor fixes * Minor fixes * Minor fixes * Adding SAM templates for "Introduction to AWS Serverless Application Model" * Fixing formatting with spaces
1 parent 4e785fd commit f6f62ea

File tree

4 files changed

+356
-154
lines changed

4 files changed

+356
-154
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: 'AWS::Serverless-2016-10-31'
3+
Description: Baeldung Serverless Application Model Example with Implicit API Definition
4+
Globals:
5+
Api:
6+
EndpointConfiguration: REGIONAL
7+
Name: "TestAPI"
8+
Resources:
9+
PersonTable:
10+
Type: AWS::Serverless::SimpleTable
11+
Properties:
12+
PrimaryKey:
13+
Name: id
14+
Type: Number
15+
TableName: Person
16+
StorePersonFunction:
17+
Type: AWS::Serverless::Function
18+
Properties:
19+
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleRequest
20+
Runtime: java8
21+
Timeout: 15
22+
MemorySize: 512
23+
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
24+
Policies:
25+
- DynamoDBCrudPolicy:
26+
TableName: !Ref PersonTable
27+
Environment:
28+
Variables:
29+
TABLE_NAME: !Ref PersonTable
30+
Events:
31+
StoreApi:
32+
Type: Api
33+
Properties:
34+
Path: /persons
35+
Method: PUT
36+
GetPersonByPathParamFunction:
37+
Type: AWS::Serverless::Function
38+
Properties:
39+
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByPathParam
40+
Runtime: java8
41+
Timeout: 15
42+
MemorySize: 512
43+
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
44+
Policies:
45+
- DynamoDBReadPolicy:
46+
TableName: !Ref PersonTable
47+
Environment:
48+
Variables:
49+
TABLE_NAME: !Ref PersonTable
50+
Events:
51+
GetByPathApi:
52+
Type: Api
53+
Properties:
54+
Path: /persons/{id}
55+
Method: GET
56+
GetPersonByQueryParamFunction:
57+
Type: AWS::Serverless::Function
58+
Properties:
59+
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByQueryParam
60+
Runtime: java8
61+
Timeout: 15
62+
MemorySize: 512
63+
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
64+
Policies:
65+
- DynamoDBReadPolicy:
66+
TableName: !Ref PersonTable
67+
Environment:
68+
Variables:
69+
TABLE_NAME: !Ref PersonTable
70+
Events:
71+
GetByQueryApi:
72+
Type: Api
73+
Properties:
74+
Path: /persons
75+
Method: GET
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: 'AWS::Serverless-2016-10-31'
3+
Description: Baeldung Serverless Application Model Example with Inline Swagger API Definition
4+
Resources:
5+
PersonTable:
6+
Type: AWS::Serverless::SimpleTable
7+
Properties:
8+
PrimaryKey:
9+
Name: id
10+
Type: Number
11+
TableName: Person
12+
StorePersonFunction:
13+
Type: AWS::Serverless::Function
14+
Properties:
15+
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleRequest
16+
Runtime: java8
17+
Timeout: 15
18+
MemorySize: 512
19+
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
20+
Policies:
21+
- DynamoDBCrudPolicy:
22+
TableName: !Ref PersonTable
23+
Environment:
24+
Variables:
25+
TABLE_NAME: !Ref PersonTable
26+
Events:
27+
StoreApi:
28+
Type: Api
29+
Properties:
30+
Path: /persons
31+
Method: PUT
32+
RestApiId:
33+
Ref: MyApi
34+
GetPersonByPathParamFunction:
35+
Type: AWS::Serverless::Function
36+
Properties:
37+
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByPathParam
38+
Runtime: java8
39+
Timeout: 15
40+
MemorySize: 512
41+
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
42+
Policies:
43+
- DynamoDBReadPolicy:
44+
TableName: !Ref PersonTable
45+
Environment:
46+
Variables:
47+
TABLE_NAME: !Ref PersonTable
48+
Events:
49+
GetByPathApi:
50+
Type: Api
51+
Properties:
52+
Path: /persons/{id}
53+
Method: GET
54+
RestApiId:
55+
Ref: MyApi
56+
GetPersonByQueryParamFunction:
57+
Type: AWS::Serverless::Function
58+
Properties:
59+
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByQueryParam
60+
Runtime: java8
61+
Timeout: 15
62+
MemorySize: 512
63+
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
64+
Policies:
65+
- DynamoDBReadPolicy:
66+
TableName: !Ref PersonTable
67+
Environment:
68+
Variables:
69+
TABLE_NAME: !Ref PersonTable
70+
Events:
71+
GetByQueryApi:
72+
Type: Api
73+
Properties:
74+
Path: /persons
75+
Method: GET
76+
RestApiId:
77+
Ref: MyApi
78+
MyApi:
79+
Type: AWS::Serverless::Api
80+
Properties:
81+
StageName: test
82+
EndpointConfiguration: REGIONAL
83+
DefinitionBody:
84+
swagger: "2.0"
85+
info:
86+
title: "TestAPI"
87+
paths:
88+
/persons:
89+
get:
90+
parameters:
91+
- name: "id"
92+
in: "query"
93+
required: true
94+
type: "string"
95+
x-amazon-apigateway-request-validator: "Validate query string parameters and\
96+
\ headers"
97+
x-amazon-apigateway-integration:
98+
uri:
99+
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetPersonByQueryParamFunction.Arn}/invocations
100+
responses: {}
101+
httpMethod: "POST"
102+
type: "aws_proxy"
103+
put:
104+
x-amazon-apigateway-integration:
105+
uri:
106+
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${StorePersonFunction.Arn}/invocations
107+
responses: {}
108+
httpMethod: "POST"
109+
type: "aws_proxy"
110+
/persons/{id}:
111+
get:
112+
parameters:
113+
- name: "id"
114+
in: "path"
115+
required: true
116+
type: "string"
117+
responses: {}
118+
x-amazon-apigateway-integration:
119+
uri:
120+
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetPersonByPathParamFunction.Arn}/invocations
121+
responses: {}
122+
httpMethod: "POST"
123+
type: "aws_proxy"
124+
x-amazon-apigateway-request-validators:
125+
Validate query string parameters and headers:
126+
validateRequestParameters: true
127+
validateRequestBody: false

0 commit comments

Comments
 (0)