예제 #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
예제 #2
0
            )

# Create function from zip file
scan_fn = lambda_.Function(
    'DynamoImagesScan',
    s3_bucket=web_bucket.id,
    s3_key=LAMBDA_VERSION+'/'+LAMBDA_SCAN_PACKAGE,
    handler="lambda_scan.handler",
    runtime="python3.7",
    role=iam.lambda_role.arn,
    environment={"variables": {"DYNAMODB_TABLE": db.id}}
)

# Create endpoint using API Gateway
scan_api = apigateway.RestApi(
    str(scan_fn.id),
    description='Pulumi Lambda API Gateway Example'
)

proxy_root_met = apigateway.Method(
    'proxy_root',
    rest_api=scan_api,
    resource_id=scan_api.root_resource_id,
    http_method='ANY',
    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,
예제 #3
0
mime_type, _ = mimetypes.guess_type(LAMBDA_PACKAGE)
obj = s3.BucketObject(LAMBDA_VERSION + '/' + LAMBDA_PACKAGE,
                      bucket=bucket.id,
                      source=FileAsset(LAMBDA_PACKAGE),
                      content_type=mime_type)

example_fn = lambda_.Function(
    'ServerlessExample',
    s3_bucket=bucket.id,
    s3_key=LAMBDA_VERSION + '/' + LAMBDA_PACKAGE,
    handler="lambda.handler",
    runtime="python3.7",
    role=iam.lambda_role.arn,
)

example_api = apigateway.RestApi(
    'ServerlessExample', description='Pulumi Lambda API Gateway Example')

proxy_root_met = apigateway.Method('proxy_root',
                                   rest_api=example_api,
                                   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)
예제 #4
0
    uri_string = "arn:aws:apigateway:{region}:lambda:path/2015-03-31/functions/{lambdaArn}/invocations".format(
        region=region, lambdaArn=lambda_arn)
    return ({
        "x-amazon-apigateway-any-method": {
            "x-amazon-apigateway-integration": {
                "uri": uri_string,
                "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,
    )
예제 #5
0
        passthroughBehavior: "when_no_match"
        type: "AWS_PROXY"
        uri: """

# We are creating the body via apply & concat: https://www.pulumi.com/docs/intro/concepts/inputs-outputs/#outputs-and-strings
# invoke_arn: https://www.pulumi.com/docs/reference/pkg/aws/lambda/function/#invoke_arn_python
# You can pass in any # of lambda functions on 1 api gateway with this solution
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",
예제 #6
0
    handler="handler.lambda_handler",
    role=example_role.arn,
    runtime="python3.8",
    timeout=30,
    opts=ResourceOptions(depends_on=[environment]),
    **get_environment_function_args(environment),
)

logs = cloudwatch.LogGroup(
    "exampleLogGroup",
    name=example_function.name.apply(lambda name: f"/aws/lambda/{name}"),
)

# API Gateway

gateway = apigateway.RestApi("exampleApi")

resource = apigateway.Resource(
    "exampleResource",
    parent_id=gateway.root_resource_id,
    path_part="{proxy+}",
    rest_api=gateway.id,
)

resources = [resource.id, gateway.root_resource_id]
methods = []
integrations = []

for i, resource_id in enumerate(resources):

    method = apigateway.Method(
예제 #7
0
import json

from pulumi_aws import apigateway
from pulumi_aws import iam
from pulumi_aws import lambda_

MODULE_NAME = "morguebot"

rest_api = apigateway.RestApi(MODULE_NAME)

resource = apigateway.Resource(
    MODULE_NAME,
    rest_api=rest_api,
    parent_id=rest_api.root_resource_id,
    path_part="dungeon_gossiper",
)

lambda_arn = "arn:aws:lambda:us-west-2:851075464416:function:lambda-authorizer"


def authorizer_role_policy():
    return json.dumps({
        "Version":
        "2012-10-17",
        "Statement": [{
            "Effect": "Allow",
            "Action": ["lambda:InvokeFunction"],
            "Resource": lambda_arn,
        }],
    })
예제 #8
0
schemes:
  - "https"
paths:
  /test:
    post:
      responses: {}
      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]))