예제 #1
0
 def add_method(resource, method='GET'):
     return self.add_resource(
         apigateway.Method(
             f'{method}{resource.title}',
             RestApiId=Ref(rest_api),
             ResourceId=Ref(resource),
             AuthorizationType='NONE',
             HttpMethod=method,
             Integration=apigateway.Integration(
                 f'{method}{resource.title}Integration',
                 Type='AWS_PROXY',
                 Uri=Join('', [
                     'arn:aws:apigateway:', Region,
                     ':lambda:path/2015-03-31/functions/',
                     Ref(self._lambda_function), '/invocations'
                 ]),
                 IntegrationHttpMethod='POST')))
예제 #2
0
    def add_service_discovery_api(self, rest_api: apigateway.RestApi):
        well_known = self.add_resource(
            apigateway.Resource(
                'Apiwellknown',
                RestApiId=Ref(rest_api),
                PathPart='.well-known',
                ParentId=GetAtt(rest_api, 'RootResourceId'),
            ))

        terraform_json = self.add_resource(
            apigateway.Resource('Apiwellknownterraformjson',
                                RestApiId=Ref(rest_api),
                                PathPart='terraform.json',
                                ParentId=Ref(well_known)))

        service_discovery = self.add_resource(
            apigateway.Method(
                'GETwellknownterraformjson',
                RestApiId=Ref(rest_api),
                ResourceId=Ref(terraform_json),
                AuthorizationType='NONE',
                HttpMethod='GET',
                Integration=apigateway.Integration(
                    'GETwellknownterraformjsonIntegration',
                    Type='MOCK',
                    IntegrationResponses=[
                        apigateway.IntegrationResponse(
                            StatusCode='200',
                            ResponseTemplates={
                                'application/json':
                                json.dumps({'modules.v1': '/v1/'})
                            })
                    ],
                    RequestTemplates={
                        'application/json': json.dumps({'statusCode': 200})
                    },
                ),
                MethodResponses=[
                    apigateway.MethodResponse(
                        StatusCode='200',
                        ResponseModels={'application/json': 'Empty'})
                ]))

        return service_discovery
예제 #3
0
파일: gdack.py 프로젝트: gkrizek/gdack
apiResource = t.add_resource(api.Resource(
    "apiResource",
    RestApiId=Ref(restApi),
    PathPart="{proxy+}",
    ParentId=GetAtt(restApi, "RootResourceId"),
))

apiMethod = t.add_resource(api.Method(
    "apiMethod",
    DependsOn='lambdaFunction',
    RestApiId=Ref(restApi),
    AuthorizationType="NONE",
    ResourceId=Ref(apiResource),
    HttpMethod="ANY",
    Integration=api.Integration(
        Credentials=GetAtt(apiRole, "Arn"),
        Type="AWS_PROXY",
        IntegrationHttpMethod='ANY',
        Uri=Join("", [
            "arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/",
            GetAtt(lambdaFunction, "Arn"),
            "/invocations"
        ])
    )
))

stageName = "v1"

apiDeployment = t.add_resource(api.Deployment(
    "apiDeployment",
    DependsOn="apiMethod",
    RestApiId=Ref(restApi),
 apigateway.Method(
     "APIFirstResourceMethodGET",
     ApiKeyRequired=False,
     AuthorizationType="NONE",
     HttpMethod="GET",
     ResourceId=Ref(api_first_resource),
     RestApiId=Ref(api),
     Integration=apigateway.Integration(
         Type="AWS",
         IntegrationHttpMethod="POST",
         Uri=Join("", [
             "arn:aws:apigateway:",
             Ref("AWS::Region"), ":lambda:path/2015-03-31/functions/",
             GetAtt(lambda_function, "Arn"), "/invocations"
         ]),
         RequestTemplates={
             "application/json":
             Join("", [
                 "{\"param1\": \"$input.params('param1')\", \"param2\": \"$input.params('param2')\"}"
             ])
         },
         IntegrationResponses=[
             apigateway.IntegrationResponse("IntegrationResponse",
                                            StatusCode="200",
                                            ResponseTemplates={
                                                "application/json":
                                                "$input.params('whatever')"
                                            }),
             apigateway.IntegrationResponse(
                 "IntegrationResponse",
                 StatusCode="404",
                 SelectionPattern="[a-zA-Z]+.*",  # any error
                 ResponseTemplates={
                     "application/json": "$input.params('whatever')"
                 }),
         ]),
     RequestParameters={
         "method.request.path.param1": True,
         "method.request.querystring.param2": True
     },
     MethodResponses=[
         apigateway.MethodResponse("APIResponse", StatusCode="200"),
         apigateway.MethodResponse("APIResponse", StatusCode="404")
     ]))
예제 #5
0
파일: jr-api.py 프로젝트: romcab/learn_cfn
api_image_method = template.add_resource(
    apigateway.Method("auth",
                      ResourceId="auth",
                      ApiKeyRequired=False,
                      AuthorizationType="NONE",
                      HttpMethod="PUT",
                      RestApiId=Ref(api),
                      Integration=apigateway.Integration(
                          Uri="",
                          IntegrationResponses=[
                              apigateway.IntegrationResponse(
                                  "Default",
                                  StatusCode="200",
                              ),
                              apigateway.IntegrationResponse(
                                  "Error",
                                  StatusCode="400",
                              )
                          ],
                          PassthroughBehavior="when_no_match",
                          IntegrationHttpMethod="POST",
                          ContentHandling="CONVERT_TO_TEXT",
                          Type="AWS"),
                      MethodResponses=[
                          apigateway.MethodResponse(
                              "Success",
                              StatusCode="200",
                          ),
                          apigateway.MethodResponse("Error", StatusCode="400")
                      ]))
예제 #6
0
        AuthorizerCredentials=GetAtt(authorizer_credentials, "Arn"),
        IdentitySource="method.request.header.Attestation",
        AuthorizerUri=lambda_invocation_arn(authorizer_lambda)))

android_resource = template.add_resource(
    apigateway.Resource('AndroidResource',
                        RestApiId=Ref(restapi),
                        PathPart='android',
                        ParentId=GetAtt(restapi, 'RootResourceId')))

root_method = template.add_resource(
    apigateway.Method('RootMethod',
                      RestApiId=Ref(restapi),
                      ResourceId=GetAtt(restapi, 'RootResourceId'),
                      HttpMethod='POST',
                      AuthorizationType='CUSTOM',
                      AuthorizerId=Ref(devices_authorizer),
                      Integration=apigateway.Integration(
                          Type='MOCK',
                          IntegrationHttpMethod='POST',
                      )))

android_register_resource = template.add_resource(
    apigateway.Resource('AndroidRegisterResource',
                        RestApiId=Ref(restapi),
                        ParentId=Ref(android_resource),
                        PathPart='register'))

android_register_lambda = androidregister.generate(template)

android_register_permission = template.add_resource(
    awslambda.Permission(