https://serverless-stack.com/ logo
#sst
Title
# sst
a

Adrián Mouly

11/26/2021, 4:44 AM
I want to connect my newly created
DockerImageFunction
to an existing API GW v2 created with
Api
construct. Can I use the existing
addRoutes
method from
Api
or I have to level down to the CDK gw-integration construct? I did the integration this way:
Copy code
myApi.httpApi.addRoutes({
      path: '/books',
      methods: [HttpMethod.GET],
      integration: new LambdaProxyIntegration({
        handler: lambda,
      }),
    });
But maybe there is a cleaner way?
g

George Evans

11/26/2021, 9:44 AM
Hi Adrian, I was implementing this last week and ended up using CDK to add the route.
Copy code
const processFunc = new lambda.DockerImageFunction(this, "ProcessGifUrl", {
      code: lambda.DockerImageCode.fromImageAsset("./", { file :"infrastructure/Dockerfile" }),
      timeout: Duration.seconds(30),
      memorySize: 1024,
      environment: {
        S3_ASSETS_BUCKET: bucket.s3Bucket.bucketName
      }
    });
    const integration = new LambdaIntegration(processFunc);
    const resource = api.restApi.root.addResource("process-gif", {
      defaultMethodOptions: {
        apiKeyRequired: true,
        authorizationType:  AuthorizationType.NONE,
      }
    });

    resource.addMethod("POST", integration)
@Frank created an issue for allowing all lambda function definitions to work with SST: https://github.com/serverless-stack/serverless-stack/issues/1078
a

Adrián Mouly

11/26/2021, 12:24 PM
Nice, that makes sense, thanks for sharing.
f

Frank

11/26/2021, 1:11 PM
Thanks @George Evans!
Looks like time to bump up the priority on this.