is it possible to add CORS / OPTIONS methods with ...
# yaml
g
is it possible to add CORS / OPTIONS methods with mock integrations using the Crosswalk
api-gateway
provider? For example I'm reading here: https://www.pulumi.com/registry/packages/aws-apigateway/api-docs/restapi/ This is where I've got up to
Copy code
##
  # Admin
  # A REST API to route requests to the admin/config Lambda functions
  api_admin:
    type: aws-apigateway:RestAPI
    options:
      version: 2.0.1
    properties:
      routes:
        ##
        # Lambda targets
        # CKO resource name: auth
        - eventHandler: ${lambda_admin_auth}
          method: GET
          path: /admin/auth        
        # CORS / OPTIONS stuff
        - path: /admin/auth
          method: OPTIONS
          target:
            type: mock
            uri: "what"
I tried importing a working manually created resource to see what the configuration in Pulumi would be like, but unfortunately AWS does not set an 'integration id' on MOCK integrations, therefore I cannot import it.
Copy code
# Pulumi import format: pulumi import aws:apigatewayv2/integrationResponse:IntegrationResponse newResourceName api-id/integration-id/integration-response-id
I found this (screenshot) which looks the most promising. But the Map<Property Map> doesn't link to anything.
I'm trying to achieve this, but in yaml
In javascript it looks like this
Copy code
gatewayResponses: {
    DEFAULT_4XX: {
      statusCode: 400,
      responseTemplates: {
        'application/json': '{"message":$context.error.messageString}',
      },
      responseParameters: {
        'gatewayresponse.header.Access-Control-Allow-Origin': "'*'",
        'gatewayresponse.header.Access-Control-Allow-Headers': "'*'",
        'gatewayresponse.header.Access-Control-Allow-Methods': "'*'",
        'gatewayresponse.header.Access-Control-Allow-Credentials': "'*'",
      },
    },
Alternatively something like this:
Copy code
path: '/{proxy+}',
    method: 'OPTIONS',
    eventHandler: async () => {
      return {
        body: '',
        statusCode: 200,
        headers: {
          'Access-Control-Allow-Origin': '*',
          'Access-Control-Allow-Credentials': 'true',
          'Access-Control-Allow-Methods':
          'GET, POST, OPTIONS, PUT, PATCH, DELETE',
          'Access-Control-Allow-Headers':
          'Origin, X-Requested-With, Content-Type, Accept, Authorization',
       },
      }
    },
I tried this but get a weird error
Copy code
api_app:
    type: aws-apigateway:RestAPI
    options:
      version: 2.0.1
    properties:
      stageName: ${pulumi.stack}
      routes:
        # <https://www.pulumi.com/registry/packages/aws-apigateway/api-docs/restapi/#target>
        - localPath: ${confFrontendCompiledFilesPath}
          method: GET
          path: /
        - path: /{proxy+}
          method: OPTIONS
      gatewayResponses:
        statusCode: 200
        responseTemplates:
          application/json: '{"statusCode": 200}'
        responseParameters:
          gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
          gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
          gatewayresponse.header.Access-Control-Allow-Methods: "'*'"
          gatewayresponse.header.Access-Control-Allow-Credentials: "'*'"
The error:
Copy code
error: Error: Non-exhaustive match for route
        at createSwaggerSpec (/snapshot/pulumi-resource-aws-apigateway/bin/apigateway/api.js:272:19)
        at createAPI (/snapshot/pulumi-resource-aws-apigateway/bin/apigateway/api.js:125:24)
        at /snapshot/pulumi-resource-aws-apigateway/bin/restAPI.js:25:40
        at /snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:257:35
        at Generator.next (<anonymous>)
        at /snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:21:71
        at new Promise (<anonymous>)
        at __awaiter (/snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:17:12)
        at applyHelperAsync (/snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:236:12)
        at /snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:190:65
    error: an unhandled error occurred: waiting for RPCs: rpc error: code = Unknown desc = Non-exhaustive match for route

    Error: Non-exhaustive match for route: Error: Non-exhaustive match for route
        at createSwaggerSpec (/snapshot/pulumi-resource-aws-apigateway/bin/apigateway/api.js:272:19)
        at createAPI (/snapshot/pulumi-resource-aws-apigateway/bin/apigateway/api.js:125:24)
        at /snapshot/pulumi-resource-aws-apigateway/bin/restAPI.js:25:40
        at /snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:257:35
        at Generator.next (<anonymous>)
        at /snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:21:71
        at new Promise (<anonymous>)
        at __awaiter (/snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:17:12)
        at applyHelperAsync (/snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:236:12)
        at /snapshot/pulumi-resource-aws-apigateway/node_modules/@pulumi/pulumi/output.js:190:65
I seem to have managed to get something working.
Copy code
- path: /admin/auth
          method: OPTIONS
          target:
            type: mock
            uri: ""
Now I just need to figure out how to get the header mappings like in the manually created one
So I managed to get it to accept the syntax, but it's apparently not advisable to touch gatewayResponses so I'm abandoning this for now, I'm just going to do it the manual way using the apigatewayv2 instead of the awsx provider.