How to use the @pulumi/awsx.apigateway function in @pulumi/awsx

To help you get started, we’ve selected a few @pulumi/awsx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulumi / pulumi-awsx / nodejs / examples / ec2 / update2 / ec2.ts View on Github external
function errorJSON(err: any) {
    const result: any = Object.create(null);
    Object.getOwnPropertyNames(err).forEach(key => result[key] = err[key]);
    return result;
}

function handleError(err: Error) {
    console.error(errorJSON(err));
    return {
        statusCode: 500,
        body: JSON.stringify(errorJSON(err)),
    };
}

// expose some APIs meant for testing purposes.
const api = new awsx.apigateway.API("containers", {
    routes: [{
        path: "/test",
        method: "GET",
        eventHandler: async (req) => {
            try {
                return {
                    statusCode: 200,
                    body: JSON.stringify({
                        nginx: nginxListener.endpoint.get(),
                        nginx2: builtServiceListener.endpoint.get(),
                    }),
                };
            } catch (err) {
                return handleError(err);
            }
        },
github pulumi / pulumi-awsx / nodejs / examples / nlb / fargate / fargate.ts View on Github external
const result: any = Object.create(null);
    Object.getOwnPropertyNames(err).forEach(key => result[key] = err[key]);
    result.florp = "blopr";
    return result;
}

function handleError(err: Error) {
    console.error(errorJSON(err));
    return {
        statusCode: 500,
        body: JSON.stringify(errorJSON(err)),
    };
}

// expose some APIs meant for testing purposes.
const api = new awsx.apigateway.API("containers", {
    routes: [{
        path: "/test",
        method: "GET",
        eventHandler: async (req) => {
            try {
                return {
                    statusCode: 200,
                    body: JSON.stringify({
                        nginx: nginxListener.endpoint.get(),
                        nginx2: builtServiceListener.endpoint.get(),
                    }),
                };
            } catch (err) {
                return handleError(err);
            }
        },
github pulumi / examples / aws-ts-apigateway / index.ts View on Github external
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

// Create a mapping from 'route' to a count
const counterTable = new aws.dynamodb.Table("counterTable", {
    attributes: [{
        name: "id",
        type: "S",
    }],
    hashKey: "id",
    readCapacity: 5,
    writeCapacity: 5,
});

// Create an API endpoint
const endpoint = new awsx.apigateway.API("hello-world", {
    routes: [{
        path: "/{route+}",
        method: "GET",
        eventHandler: async (event) => {
            const route = event.pathParameters!["route"];
            console.log(`Getting count for '${route}'`);

            const client = new aws.sdk.DynamoDB.DocumentClient();

            // get previous value and increment
            // reference outer `counterTable` object
            const tableData = await client.get({
                TableName: counterTable.name.get(),
                Key: { id: route },
                ConsistentRead: true,
            }).promise();
github mapbox / asset-tracking / src / index.js View on Github external
],
  hashKey: "id",
  ttl: {
    attributeName: "expiration",
    enabled: true
  },
  //* If you would like provisioned Dynamo, swap billingMode via the comments below.
  // billingMode:"PROVISIONED",
  // readCapacity: 5,
  // writeCapacity: 5
  billingMode: "PAY_PER_REQUEST"
});

//* Create API to read Dynamo
//* This will scan the table and convert it to geojson for consumption via GL-JS
const endpoint = new awsx.apigateway.API("mapboxQuery", {
  routes: [
    {
      path: "/",
      method: "GET",
      eventHandler: (request, ctx, cb) => {
        const AWS = require("aws-sdk");
        const ddb = new AWS.DynamoDB.DocumentClient({
          apiVersion: "2012-10-08"
        });
        const tableName = assetTable.name.value;
        const params = {
          TableName: tableName
        };
        ddb.scan(params, (err, data) => {
          if (data.Items.length > 0) {
            //All data processing occurs here
github fanout / apollo-serverless-demo / index.ts View on Github external
const config = {
  // like https://api.fanout.io/realm/{realm-id}?iss={realm-id}&key=base64:{realm-key}
  gripUrl: process.env.GRIP_URL || configFromPulumi.gripUrl,
  name: configFromPulumi.name,
};

const fanoutGraphqlAwsAppPulumiName = config.name;

const fanoutGraphqlAwsApp = FanoutGraphqlAwsApp(
  `${fanoutGraphqlAwsAppPulumiName}-lambda`,
  {
    grip: config.gripUrl ? { url: config.gripUrl } : false,
  },
);

const endpoint = new awsx.apigateway.API(
  `${fanoutGraphqlAwsAppPulumiName}-api-gateway`,
  {
    routes: fanoutGraphqlAwsApp.routes,
  },
);

/** URL of FanoutGraphglAwsApp API Gateway */
export const url = endpoint.url;
github pulumi / pulumi-awsx / nodejs / examples / api / step2 / index.ts View on Github external
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import * as awsx from "@pulumi/awsx";

const api = new awsx.apigateway.API("myapi", {
    routes: [{
        path: "/b",
        method: "GET",
        eventHandler: async (event) => {
            return {
                statusCode: 200,
                body: "<h1>Hello world!</h1>",
            };
        }
    }],
});

export const url = api.url;
github pulumi / examples / aws-ts-pulumi-webhooks / index.ts View on Github external
}

    const payload = req.body!.toString();
    const hmacAlg = crypto.createHmac("sha256", stackConfig.sharedSecret);
    const hmac = hmacAlg.update(payload).digest("hex");

    const result = crypto.timingSafeEqual(Buffer.from(webhookSig), Buffer.from(hmac));
    if (!result) {
        console.log(`Mismatch between expected signature and HMAC: '${webhookSig}' vs. '${hmac}'.`);
        return { statusCode: 400, body: "Unable to authenticate message: Mismatch between signature and HMAC" };
    }

    return undefined;
}

const webhookHandler = new awsx.apigateway.API("pulumi-webhook-handler", {
    routes: [{
        path: "/",
        method: "GET",
        eventHandler: async () => ({
            statusCode: 200,
            body: "🍹 Pulumi Webhook Responder🍹\n",
        }),
    }, {
        path: "/",
        method: "POST",
        eventHandler: async (req) => {
            logRequest(req);
            const authenticateResult = authenticateRequest(req);
            if (authenticateResult) {
                return authenticateResult;
            }
github pulumi / pulumi-awsx / nodejs / examples / api / index.ts View on Github external
authorizers: lambdaAuthorizer,
    }, {
        path: "/b",
        method: "GET",
        eventHandler: lambda,
        apiKeyRequired: true,
        authorizers: lambdaAuthorizer,
    }, {
        path: "/www",
        localPath: "www",
        requiredParameters: [{
            name: "key",
            in: "query",
        }],
        apiKeyRequired: true,
        authorizers: [awsx.apigateway.getTokenLambdaAuthorizer({
            header: "Authorization",
            handler: async (event: awsx.apigateway.AuthorizerEvent) => {
                const token = event.authorizationToken;
                if (token === "Allow") {
                    return awsx.apigateway.authorizerResponse("user", "Allow", event.methodArn);
                }
                return awsx.apigateway.authorizerResponse("user", "Deny", event.methodArn);
            },
        })],
    }, {
        path: "/rawdata",
        method: "GET",
        data: {
            "responses": {},
            "x-amazon-apigateway-request-validator": "ALL",
            "x-amazon-apigateway-integration": {
github pulumi / pulumi-awsx / nodejs / examples / metrics / index.ts View on Github external
maxMessageSize: 2048,
    messageRetentionSeconds: 86400,
    receiveWaitTimeSeconds: 10,
    tags: {
        Environment: "production",
    },
});

const queueMetric = awsx.sqs.metrics.sentMessageSize({ queue });
const queueAlarm = queueMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });

const restApi = new aws.apigateway.RestApi("MyDemoAPI", {
    description: "This is my API for demonstration purposes",
  });

const restApiMetric = awsx.apigateway.metrics.error5XX({ restApi });
const restApiAlarm = restApiMetric.createAlarm("alarm" + alarmIndex++, { threshold: 50, evaluationPeriods: 2 });

const table = new aws.dynamodb.Table("testtable", {
    attributes: [{
        name: "id",
        type: "S",
    }],
    hashKey: "id",
    readCapacity: 5,
    writeCapacity: 5,
    streamEnabled: true,
    streamViewType: "NEW_AND_OLD_IMAGES",
});

const tableMetric = awsx.dynamodb.metrics.throttledRequests({ table });
const tableAlarm = tableMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });
github pulumi / pulumi-awsx / nodejs / examples / api / index.ts View on Github external
handler: async (event: awsx.apigateway.AuthorizerEvent) => {
        return awsx.apigateway.authorizerResponse("user", "Allow", event.methodArn);
    },
    identitySource: ["method.request.querystring.auth"],

@pulumi/awsx

[![Actions Status](https://github.com/pulumi/pulumi-awsx/workflows/master/badge.svg)](https://github.com/pulumi/pulumi-awsx/actions) [![Slack](http://www.pulumi.com/images/docs/badges/slack.svg)](https://slack.pulumi.com) [![NPM version](https://badge.fur

Apache-2.0
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis