Snippets
Created by
Spenser Filler
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | Resources:
LogEventLambda:
Type: 'AWS::Lambda::Function'
Properties:
Handler: 'index.lambda_handler'
FunctionName: 'log-event-example'
Role: !Join
- ''
- - 'arn:aws:iam::'
- !Ref 'AWS::AccountId'
- ':role/LambdaBasicExecution'
Code:
ZipFile: |
def lambda_handler(event, context):
print(event)
return {
"status" : "success"
}
Runtime: python3.6
Timeout: '25'
TracingConfig:
Mode: Active
MemorySize: 128
LogEventAPI:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: 'log-event-api'
LogEventResource:
Type: 'AWS::ApiGateway::Resource'
Properties:
RestApiId: !Ref LogEventAPI
PathPart: logerror
ParentId: !GetAtt
- LogEventAPI
- RootResourceId
LogEventPOST:
Type: 'AWS::ApiGateway::Method'
Properties:
AuthorizationType: NONE
HttpMethod: POST
Integration:
Type: AWS
IntegrationHttpMethod: POST
Uri: !Join
- ''
- - 'arn:aws:apigateway:'
- !Ref 'AWS::Region'
- >-
:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:
- !Ref 'AWS::AccountId'
- :function:log-event-example
- /invocations
IntegrationResponses:
- StatusCode: 200
ResponseTemplates:
application/json: ''
ResponseParameters:
method.response.header.Access-Control-Allow-Headers: >-
'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'
method.response.header.Access-Control-Allow-Methods: '''POST,OPTIONS'''
method.response.header.Access-Control-Allow-Origin: '''*'''
PassthroughBehavior: WHEN_NO_MATCH
ResourceId: !Ref LogEventResource
RestApiId: !Ref LogEventAPI
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: Empty
LogEventOPTIONS:
Type: 'AWS::ApiGateway::Method'
Properties:
ResourceId: !Ref LogEventResource
RestApiId: !Ref LogEventAPI
AuthorizationType: NONE
HttpMethod: OPTIONS
Integration:
Type: MOCK
IntegrationResponses:
- ResponseParameters:
method.response.header.Access-Control-Allow-Headers: >-
'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'
method.response.header.Access-Control-Allow-Methods: '''POST,OPTIONS'''
method.response.header.Access-Control-Allow-Origin: '''*'''
ResponseTemplates:
application/json: ''
StatusCode: '200'
PassthroughBehavior: NEVER
RequestTemplates:
application/json: '{"statusCode": 200}'
MethodResponses:
- ResponseModels:
application/json: Empty
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
StatusCode: '200'
LogEventPermission:
DependsOn: LogEventLambda
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:invokeFunction'
FunctionName: 'log-event-example'
Principal: apigateway.amazonaws.com
SourceArn: !Join
- ''
- - 'arn:aws:execute-api:'
- !Ref 'AWS::Region'
- ':'
- !Ref 'AWS::AccountId'
- ':'
- !Ref LogEventAPI
- /*
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.