Last active
August 15, 2022 21:05
-
-
Save antklim/a17ceefad9d0e7485b492e54519ea042 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FormDataPOSTApi: | |
Type: AWS::ApiGateway::Method | |
Properties: | |
AuthorizationType: NONE | |
HttpMethod: POST | |
ResourceId: !Ref FormDataResource | |
RestApiId: !Ref APIGW | |
RequestModels: | |
application/json: !Ref FormDataInputModel | |
RequestParameters: | |
method.request.header.Content-Type: true | |
RequestValidatorId: !Ref FormDataRequestValidator | |
Integration: | |
Type: AWS | |
Credentials: !GetAtt APIGWRole.Arn | |
Uri: !Sub arn:aws:apigateway:${AWS::Region}:dynamodb:action/PutItem | |
IntegrationHttpMethod: POST | |
PassthroughBehavior: WHEN_NO_TEMPLATES | |
RequestParameters: | |
integration.request.header.Content-Type: method.request.header.Content-Type | |
RequestTemplates: | |
application/json: | | |
#set($inputRoot = $input.path('$')) | |
{ | |
"TableName": "intention", | |
"Item": { | |
"email": { | |
"S": "$inputRoot.email" | |
}, | |
"fullName": { | |
"S": "$inputRoot.fullName" | |
}, | |
"comment": { | |
"S": "$inputRoot.comment" | |
}, | |
"stage": { | |
"S": "$context.stage" | |
}, | |
"createdAt": { | |
"S": "$context.requestTimeEpoch" | |
} | |
}, | |
"ConditionExpression": "email <> :e", | |
"ExpressionAttributeValues": { | |
":e": {"S": "$inputRoot.email"} | |
} | |
} | |
application/x-www-form-urlencoded: | | |
#set( $email = '' ) | |
#set( $fullName = '' ) | |
#set( $comment = '' ) | |
#foreach( $token in $input.path('$').split('&') ) | |
#set( $keyVal = $token.split('=') ) | |
#set( $keyValSize = $keyVal.size() ) | |
#if( $keyValSize >= 1 ) | |
#set( $key = $util.urlDecode($keyVal[0]) ) | |
#if( $keyValSize >= 2 ) | |
#set( $val = $util.urlDecode($keyVal[1]) ) | |
#else | |
#set( $val = '' ) | |
#end | |
#if( $key == 'email' ) | |
#set( $email = $val ) | |
#elseif( $key == 'fullName' ) | |
#set( $fullName = $val ) | |
#elseif( $key == 'comment' ) | |
#set( $comment = $val ) | |
#end | |
#end | |
#end | |
{ | |
"TableName": "intention", | |
"Item": { | |
"email": { | |
"S": "$email" | |
}, | |
"fullName": { | |
"S": "$fullName" | |
}, | |
"comment": { | |
"S": "$comment" | |
}, | |
"stage": { | |
"S": "$context.stage" | |
}, | |
"createdAt": { | |
"S": "$context.requestTimeEpoch" | |
} | |
}, | |
"ConditionExpression": "email <> :e", | |
"ExpressionAttributeValues": { | |
":e": {"S": "$email"} | |
} | |
} | |
IntegrationResponses: | |
- StatusCode: 200 | |
SelectionPattern: 2\d{2} | |
ResponseParameters: | |
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'" | |
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" | |
method.response.header.Access-Control-Allow-Origin: "'*'" | |
ResponseTemplates: | |
application/json: | | |
{"message": "Thank you! We will keep you posted!", "statusCode": 200} | |
- StatusCode: 500 | |
ResponseParameters: | |
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'" | |
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" | |
method.response.header.Access-Control-Allow-Origin: "'*'" | |
ResponseTemplates: | |
application/json: | | |
{"message": "Oops! Something went wrong :(", "statusCode": 500} | |
MethodResponses: | |
- StatusCode: 200 | |
ResponseParameters: | |
method.response.header.Access-Control-Allow-Headers: true | |
method.response.header.Access-Control-Allow-Methods: true | |
method.response.header.Access-Control-Allow-Origin: true | |
ResponseModels: | |
application/json: !Ref FormDataOutputModel | |
- StatusCode: 500 | |
ResponseParameters: | |
method.response.header.Access-Control-Allow-Headers: true | |
method.response.header.Access-Control-Allow-Methods: true | |
method.response.header.Access-Control-Allow-Origin: true | |
ResponseModels: | |
application/json: !Ref FormDataOutputModel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment