Skip to content

Commit b16fb0f

Browse files
committed
2 parents 282f4fb + a679e13 commit b16fb0f

File tree

4 files changed

+38
-37
lines changed

4 files changed

+38
-37
lines changed

apigw-data-validation/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ After the application is deployed try the following scenarios.
4646
4747
### Create a new vehicle entering valid data:
4848
```
49-
curl --location --request POST 'https://qap9jh21xk.execute-api.us-west-2.amazonaws.com/Prod/' \
49+
curl --location --request POST 'https://{api-id}.execute-api.{region}.amazonaws.com/Prod/vehicle' \
5050
--header 'Content-Type: application/json' \
5151
--data-raw '{
52-
"make":"MINI",
53-
"model":"Countryman",
54-
"year": 2010
52+
"make": "MINI",
53+
"model": "Countryman",
54+
"year": 2020
5555
}'
5656
```
57-
Expected response: `{"message": "Data vbalidation succeded", "data": {"make": "MINI", "model": "Countryman", "year": 2010}}`
57+
Expected response: `{"message": "Data validation succeded", "data": {"make": "MINI", "model": "Countryman", "year": 2020}}`
5858
### Now enter a year less than 2010
5959
```
60-
curl --location --request POST 'https://qap9jh21xk.execute-api.us-west-2.amazonaws.com/Prod/' \
60+
curl --location --request POST 'https://{api-id}.execute-api.{region}.amazonaws.com/Prod/vehicle' \
6161
--header 'Content-Type: application/json' \
6262
--data-raw '{
63-
"make":"MINI",
64-
"model":"Countryman",
65-
"year": 2002
63+
"make": "MINI",
64+
"model": "Countryman",
65+
"year": 2009
6666
}'
6767
```
6868
Expected response: `{"message": "Invalid request body"}`

apigw-data-validation/src/app.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import json
2+
23
def lambda_handler(event, context):
3-
return {
4-
"statusCode": 200,
5-
"body": json.dumps({
6-
"message": "Data validation succeded",
7-
"data": json.loads(event["body"])
8-
}),
9-
}
4+
try:
5+
# Parse the incoming JSON body
6+
body = json.loads(event['body'])
7+
8+
return {
9+
'statusCode': 200,
10+
'body': json.dumps({
11+
'message': 'Data validation succeeded',
12+
'data': body
13+
})
14+
}
15+
except Exception as e:
16+
return {
17+
'statusCode': 400,
18+
'body': json.dumps({
19+
'message': 'Invalid request body'
20+
})
21+
}
Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
3-
Description: API Gateway data validation (uksb-1tthgi812) (tag:apigw-data-validation)
3+
Description: API Gateway data validation example (uksb-1tthgi812) (tag:apigw-data-validation)
44

55
Globals:
66
Function:
77
Timeout: 3
88

99
Resources:
10-
11-
# REST API Configuration. Creates models available for validation at each endpoint.
10+
# REST API Configuration
1211
MainApi:
1312
Type: AWS::Serverless::Api
1413
Properties:
1514
StageName: Prod
1615
Models:
17-
Vehicle: # Data model for vehicles to be validated against
16+
Vehicle:
1817
type: object
1918
required:
2019
- make
@@ -40,32 +39,22 @@ Resources:
4039
Properties:
4140
CodeUri: src/
4241
Handler: app.lambda_handler
43-
Runtime: python3.9
42+
Runtime: python3.13
4443
Architectures:
4544
- arm64
4645
Events:
4746
Process:
4847
Type: Api
4948
Properties:
5049
RestApiId: !Ref MainApi
51-
Path: /{id}
50+
Path: /vehicle
5251
Method: post
53-
RequestParameters:
54-
- method.request.querystring.order:
55-
Required: true
56-
Caching: true
57-
# - method.request.path.id:
58-
# Required: true
59-
- method.request.header.custom-agent:
60-
Required: true
6152
RequestModel:
62-
Model: Vehicle # Links available model
63-
Required: true # requires validation
64-
ValidateBody: true #Validates the request body.
65-
ValidateParameters: true #Validates the request header
53+
Model: Vehicle
54+
Required: true
55+
ValidateBody: true
6656

67-
6857
Outputs:
6958
ProcessApi:
70-
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
59+
Description: "API Gateway endpoint URL for Prod stage"
7160
Value: !Sub "https://${MainApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"

s3-lambda-resizing-dotnet/ImageResize/ImageResize.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
1616
<PackageReference Include="Amazon.Lambda.S3Events" Version="3.0.0" />
1717
<PackageReference Include="AWSSDK.S3" Version="3.7.104.2" />
18-
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
18+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
1919
</ItemGroup>
2020
</Project>

0 commit comments

Comments
 (0)