constructor()

in lib/base/oidc-resource-stack.ts [23:63]


  constructor(scope: cdk.Construct, id: string, props: OidcResourceStackProps) {
    super(scope, id, props);

    const sampleFn = new nodejslambda.NodejsFunction(this, 'oidc-resource-function', {
      entry: `${path.join(path.resolve(__dirname, '..', '..'), 'resources', 'oidc-resource', 'sample')}/handler.js`,
      handler: 'hello',
      timeout: cdk.Duration.seconds(900),
      memorySize: 3008,
    });

    const authFn = new nodejslambda.NodejsFunction(this, 'oidc-resource-auth-function', {
      entry: `${path.join(path.resolve(__dirname, '..', '..'), 'resources', 'oidc-resource', 'authorizer')}/index.js`,
      handler: 'authorizerHandler',
      timeout: cdk.Duration.seconds(900),
      memorySize: 3008,
      environment: {
        AWS_CUSTOM_AUTHORIZER_CLIENT_SECRET: props.clientSecret,
        AWS_CUSTOM_AUTHORIZER_CLIENT_ID: props.clientId,
        AWS_CUSTOM_AUTHORIZER_INTROSPECTION_ENDPOINT: props.introspectionUrl,
        COGNITO_USER_POOL_ID: props.cognitoPoolId,
      },
    });
    const api = new apigateway.RestApi(this, 'oidc-resource-api', {
      restApiName: 'oidc-resource-api',
      description: 'This service serves unicorn cookies.',
    });

    const auth = new apigateway.TokenAuthorizer(this, 'oidc-resource-authorizer', {
      handler: authFn,
    });

    const getSampleIntegration = new apigateway.LambdaIntegration(sampleFn, {
      requestTemplates: { 'application/json': '{ "statusCode": "200" }' },
    });

    api.root.addMethod('GET', getSampleIntegration, {
      authorizer: auth,
    });

    this.resourceUrl = api.url;
  }