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
Exemple #2
0
    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)
# Lambda policy name and id
pulumi.export("api_lambda_role_policy_name", api_lambda_role_policy.name)
pulumi.export("api_lambda_role_policy_id", api_lambda_role_policy.id)
# Export the name of the s3 bucket
pulumi.export('s3_bucket_name', artifacts_bucket.id)
# Export the name of the object in the s3 bucket
pulumi.export('api_airtable_layer_zip_id__s3_object',
# 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",
    source_arn=deployment.execution_arn.apply(
        lambda execution_arn: execution_arn + "*/*"),
    )

# Export the https endpoint of the running Rest API
pulumi.export("endpoint", deployment.invoke_url.apply(lambda url: url + custom_stage_name))
Exemple #4
0
            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}/*/*/*"),
    opts=ResourceOptions(depends_on=[example_function, deployment]),
)

pulumi.export("file_system_id", environment.file_system_id)
pulumi.export("vpc_id", environment.vpc_id)
pulumi.export("public_subnets", environment.public_subnet_ids)