Exemplo n.º 1
0
    def build(self):
        rest_api = apigateway.RestApi(
            self.name, opts=pulumi.ResourceOptions(depends_on=[self._lambda]))

        hello, hello_components = self._endpoint(rest_api, "hello")
        bonjour, bonjour_components = self._endpoint(rest_api, "bonjour")
        components = hello_components + bonjour_components
        deployment = apigateway.Deployment(
            self.name,
            opts=pulumi.ResourceOptions(depends_on=[rest_api, hello, bonjour] +
                                        components),
            rest_api=rest_api.id,
        )
        stage = apigateway.Stage(
            self.name,
            opts=pulumi.ResourceOptions(depends_on=[deployment]),
            deployment=deployment.id,
            rest_api=rest_api.id,
            stage_name="dev",
        )
        return rest_api
Exemplo n.º 2
0
                                   resource_id=example_api.root_resource_id,
                                   http_method='ANY',
                                   authorization='NONE')

example_root_int = apigateway.Integration(
    'lambda_root',
    rest_api=example_api,
    resource_id=proxy_root_met.resource_id,
    http_method=proxy_root_met.http_method,
    integration_http_method='POST',
    type='AWS_PROXY',
    uri=example_fn.invoke_arn)

example_dep = apigateway.Deployment(
    'example',
    rest_api=example_api,
    stage_name="example-test",
    __opts__=ResourceOptions(depends_on=[example_root_int]))

example_perm = lambda_.Permission(
    "apigw",
    statement_id="AllowAPIGatewayInvoke",
    action="lambda:InvokeFunction",
    function=example_fn,
    principal="apigateway.amazonaws.com",
    source_arn=example_dep.execution_arn.apply(lambda x: f"{x}/*/*"))

# Export the name of the bucket with lambda code
# List bucket with:
# aws s3 ls --recursive `pulumi stack output bucket_name`
export('bucket_name', bucket.id)
Exemplo n.º 3
0
    authorization='NONE'
)

scan_root_int = apigateway.Integration(
    'lambda_root',
    rest_api=scan_api,
    resource_id=proxy_root_met.resource_id,
    http_method=proxy_root_met.http_method,
    integration_http_method='POST',
    type='AWS_PROXY',
    uri=scan_fn.invoke_arn
)

scan_dep = apigateway.Deployment(
    'images_scan',
    rest_api=scan_api,
    stage_name="images_scan-dev",
    __opts__=ResourceOptions(depends_on=[scan_root_int])
)

# Set function permissions (access S3 and DynamoDB)
scan_perm = lambda_.Permission(
    "apigw",
    statement_id="AllowAPIGatewayInvoke",
    action="lambda:InvokeFunction",
    function=scan_fn,
    principal="apigateway.amazonaws.com",
    source_arn=scan_dep.execution_arn.apply(lambda x: f"{x}/*/*")
)

# Lambda function for S3 trigger
lambda_rekognition = lambda_.Function(
Exemplo n.º 4
0
                "passthroughBehavior": "when_no_match",
                "httpMethod": "POST",
                "type": "aws_proxy",
            },
        },
    })

# Create the API Gateway Rest API, using a swagger spec.
rest_api = apigateway.RestApi("api",
    body=lambda_func.arn.apply(lambda lambda_arn: swagger_spec(lambda_arn)),
    )

# Create a deployment of the Rest API.
deployment = apigateway.Deployment("api-deployment",
    rest_api=rest_api,
    # Note: Set to empty to avoid creating an implicit stage, we'll create it
    # explicitly below instead.
    stage_name="")

# Create a stage, which is an addressable instance of the Rest API. Set it to point at the latest deployment.
stage = apigateway.Stage("api-stage",
    rest_api=rest_api,
    deployment=deployment,
    stage_name=custom_stage_name,
    )

# Give permissions from API Gateway to invoke the Lambda
invoke_permission = lambda_.Permission("api-lambda-permission",
    action="lambda:invokeFunction",
    function=lambda_func,
    principal="apigateway.amazonaws.com",
Exemplo n.º 5
0
fullbody = Output.concat(f'{first_part_swagger_openapi}', f'{route_1}',
                         api_airtable.invoke_arn, f'{route_2}',
                         api_airtable.invoke_arn, f'{route_3}',
                         api_airtable.invoke_arn)

pulumi.export("fullbody", fullbody)
api_gateway = apigateway.RestApi(
    resource_name='api-gateway',
    api_key_source='HEADER',
    body=fullbody,
    description="This is the hello python apigateway with lambda integration",
)

api_gateway_deployment = apigateway.Deployment(
    'api-gateway-deployment',
    rest_api=api_gateway.id,
    description="This is the apigateway deployment",
    opts=pulumi.ResourceOptions(depends_on=[api_gateway]))

api_gateway_stage = apigateway.Stage(
    'api-gateway-stage',
    stage_name='dev',
    rest_api=api_gateway.id,
    deployment=api_gateway_deployment.id,
    description="This is the apigateway stage",
    opts=pulumi.ResourceOptions(depends_on=[api_gateway]))

# Exports
# Lambda Roles   id and arn
pulumi.export("api_lambda_role_id", api_lambda_role.id)
pulumi.export("api_lambda_role_arn", api_lambda_role.arn)
Exemplo n.º 6
0
        resource_id=resource_id,
        http_method=method.http_method,
        integration_http_method="POST",
        type="AWS_PROXY",
        uri=example_function.arn.apply(
            lambda arn:
            f"arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/{arn}/invocations"
        ),
    )

    methods.append(method)
    integrations.append(integration)

deployment = apigateway.Deployment(
    "exampleDeployment",
    rest_api=gateway.id,
    opts=ResourceOptions(depends_on=[*methods, *integrations]),
)

stage = apigateway.Stage("exampleStage",
                         deployment=deployment.id,
                         rest_api=gateway.id,
                         stage_name="dev")

lambda_permission = lambda_.Permission(
    "lambdaPermission",
    action="lambda:InvokeFunction",
    function=example_function.name,
    principal="apigateway.amazonaws.com",
    source_arn=gateway.execution_arn.apply(
        lambda execution_arn: f"{execution_arn}/*/*/*"),
Exemplo n.º 7
0
      x-amazon-apigateway-integration:
        httpMethod: "POST"
        passthroughBehavior: "when_no_match"
        type: "AWS_PROXY"
        uri: """

final_output = Output.concat(f'{first_part}', api_airtable.invoke_arn)
api_gateway = apigateway.RestApi(
    'api-gateway',
    body=final_output,
    api_key_source='HEADER',
    description="This is the hello python apigateway with lambda integration",
)

api_gateway_deployment = apigateway.Deployment(
    'api-gateway-deployment',
    rest_api=api_gateway.id,
    opts=pulumi.ResourceOptions(depends_on=[api_gateway]))

api_gateway_stage = apigateway.Stage(
    'api-gateway-stage',
    stage_name='dev',
    rest_api=api_gateway.id,
    deployment=api_gateway_deployment.id,
    opts=pulumi.ResourceOptions(depends_on=[api_gateway]))

pulumi.export("api_lambda_role_name", api_lambda_role.name)
pulumi.export("api_lambda_role_id", api_lambda_role.id)
pulumi.export("api_lambda_role_arn", api_lambda_role.arn)

pulumi.export("api_lambda_role_policy_name", api_lambda_role_policy.name)
pulumi.export("api_lambda_role_policy_id", api_lambda_role_policy.id)