|
| 1 | +Transform: |
| 2 | +- AWS::Serverless-2016-10-31 |
| 3 | +Resources: |
| 4 | + ApiGatewayCognitoExecutionRole4F7CB5C8: |
| 5 | + Type: AWS::IAM::Role |
| 6 | + Properties: |
| 7 | + AssumeRolePolicyDocument: |
| 8 | + Statement: |
| 9 | + - Action: sts:AssumeRole |
| 10 | + Effect: Allow |
| 11 | + Principal: |
| 12 | + Service: apigateway.amazonaws.com |
| 13 | + Version: '2012-10-17' |
| 14 | + Policies: |
| 15 | + - PolicyDocument: |
| 16 | + Statement: |
| 17 | + - Action: lambda:Invoke* |
| 18 | + Effect: Allow |
| 19 | + Resource: |
| 20 | + Fn::GetAtt: |
| 21 | + - LambdaFunction7804BD21 |
| 22 | + - Arn |
| 23 | + Version: '2012-10-17' |
| 24 | + PolicyName: apigInvokeLambda |
| 25 | + LambdaFunctionServiceRoleD6E423C9: |
| 26 | + Type: AWS::IAM::Role |
| 27 | + Properties: |
| 28 | + AssumeRolePolicyDocument: |
| 29 | + Statement: |
| 30 | + - Action: sts:AssumeRole |
| 31 | + Effect: Allow |
| 32 | + Principal: |
| 33 | + Service: lambda.amazonaws.com |
| 34 | + Version: '2012-10-17' |
| 35 | + ManagedPolicyArns: |
| 36 | + - Fn::Join: |
| 37 | + - '' |
| 38 | + - - 'arn:' |
| 39 | + - Ref: AWS::Partition |
| 40 | + - :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole |
| 41 | + LambdaFunctionServiceRoleDefaultPolicyF01A7EDC: |
| 42 | + Type: AWS::IAM::Policy |
| 43 | + Properties: |
| 44 | + PolicyDocument: |
| 45 | + Statement: |
| 46 | + - Action: sns:Publish |
| 47 | + Effect: Allow |
| 48 | + Resource: '*' |
| 49 | + Version: '2012-10-17' |
| 50 | + PolicyName: LambdaFunctionServiceRoleDefaultPolicyF01A7EDC |
| 51 | + Roles: |
| 52 | + - Ref: LambdaFunctionServiceRoleD6E423C9 |
| 53 | + LambdaFunction7804BD21: |
| 54 | + Type: AWS::Lambda::Function |
| 55 | + Properties: |
| 56 | + Code: |
| 57 | + ZipFile: | |
| 58 | + exports.handler = async (event, context, callback) => { |
| 59 | + const auth = event.queryStringParameters.authorization |
| 60 | + const policyDocument = { |
| 61 | + Version: '2012-10-17', |
| 62 | + Statement: [{ |
| 63 | + Action: 'execute-api:Invoke', |
| 64 | + Effect: auth && auth.toLowerCase() === 'allow' ? 'Allow' : 'Deny', |
| 65 | + Resource: event.methodArn |
| 66 | + }] |
| 67 | + } |
| 68 | + |
| 69 | + return { |
| 70 | + principalId: 'user', |
| 71 | + context: {}, |
| 72 | + policyDocument |
| 73 | + } |
| 74 | + } |
| 75 | + Role: |
| 76 | + Fn::GetAtt: |
| 77 | + - LambdaFunctionServiceRoleD6E423C9 |
| 78 | + - Arn |
| 79 | + Handler: index.handler |
| 80 | + Runtime: nodejs16.x |
| 81 | + MyCognitoUserPool: |
| 82 | + Type: AWS::Cognito::UserPool |
| 83 | + Properties: |
| 84 | + UserPoolName: MyCognitoUserPool |
| 85 | + ApiGatewayCognitoService15108F0B: |
| 86 | + Type: AWS::Serverless::Api |
| 87 | + Properties: |
| 88 | + StageName: prod |
| 89 | + Auth: |
| 90 | + AddDefaultAuthorizerToCorsPreflight: false |
| 91 | + Authorizers: |
| 92 | + CognitoAuthorizer: |
| 93 | + UserPoolArn: |
| 94 | + Fn::GetAtt: MyCognitoUserPool.Arn |
| 95 | + DefaultAuthorizer: CognitoAuthorizer |
| 96 | + DefinitionBody: |
| 97 | + openapi: 3.0.2 |
| 98 | + info: |
| 99 | + title: RxtHofApprovalServiceLambdaCognito |
| 100 | + version: '2018-05-10' |
| 101 | + paths: |
| 102 | + /reviews: |
| 103 | + post: |
| 104 | + operationId: CreateReview |
| 105 | + requestBody: |
| 106 | + content: |
| 107 | + application/json: |
| 108 | + schema: |
| 109 | + $ref: '#/components/schemas/CreateReviewRequestContent' |
| 110 | + required: true |
| 111 | + responses: |
| 112 | + '200': |
| 113 | + description: CreateReview 200 response |
| 114 | + headers: |
| 115 | + Access-Control-Allow-Origin: |
| 116 | + schema: |
| 117 | + type: string |
| 118 | + Access-Control-Expose-Headers: |
| 119 | + schema: |
| 120 | + type: string |
| 121 | + content: |
| 122 | + application/json: |
| 123 | + schema: |
| 124 | + $ref: '#/components/schemas/CreateReviewResponseContent' |
| 125 | + x-amazon-apigateway-integration: |
| 126 | + type: aws_proxy |
| 127 | + httpMethod: POST |
| 128 | + uri: |
| 129 | + Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction7804BD21.Arn}/invocations |
| 130 | + credentials: |
| 131 | + Fn::Sub: ${ApiGatewayCognitoExecutionRole4F7CB5C8.Arn} |
| 132 | + responses: |
| 133 | + default: |
| 134 | + statusCode: '200' |
| 135 | + responseParameters: |
| 136 | + method.response.header.Access-Control-Allow-Origin: "'*'" |
| 137 | + method.response.header.Access-Control-Expose-Headers: "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid'" |
| 138 | + components: |
| 139 | + schemas: |
| 140 | + CreateReviewRequestContent: |
| 141 | + type: object |
| 142 | + properties: |
| 143 | + reviewId: |
| 144 | + type: string |
| 145 | + CreateReviewResponseContent: |
| 146 | + type: object |
| 147 | + properties: |
| 148 | + reviewId: |
| 149 | + type: string |
| 150 | + securitySchemes: |
| 151 | + aws.auth.sigv4: |
| 152 | + type: apiKey |
| 153 | + description: AWS Signature Version 4 authentication |
| 154 | + name: Authorization |
| 155 | + in: header |
| 156 | + x-amazon-apigateway-authtype: awsSigv4 |
| 157 | + security: |
| 158 | + - aws.auth.sigv4: [] |
| 159 | + x-amazon-apigateway-gateway-responses: |
| 160 | + DEFAULT_5XX: |
| 161 | + responseTemplates: |
| 162 | + application/json: '{"message":$context.error.messageString}' |
| 163 | + responseParameters: |
| 164 | + gatewayresponse.header.Access-Control-Allow-Origin: "'*'" |
| 165 | + OpenApiVersion: '2.0' |
| 166 | + TracingEnabled: true |
0 commit comments