https://pulumi.com logo
#aws
Title
# aws
s

salmon-thailand-93496

06/03/2023, 1:16 AM
I did an update to the latest versions of the libraries after a long time, and I’m having trouble with the type of function to feed into a route in API Gateway. It looks like this:
Copy code
import * as apigateway from "@pulumi/aws-apigateway";
import * as aws from "@pulumi/aws";

const lambda = new aws.lambda.Function(lambdaName, {
    name: lambdaName,
    code: repositoryImage.imageUri,
    handler: 'index.handler',
    ...
});

const api = new apigateway.RestAPI(apiName, {
    routes: [{
        path: "/route",
        method: "POST",
        eventHandler: lambda
    }]
})
This construction used to work for me in the earlier versions, but right now, it gives me this error:
Copy code
TS2322: Type 'Function' is not assignable to type 'Input<Function> | undefined'.   Type 'Function' is missing the following properties from type 'Function': ephemeralStorage, qualifiedInvokeArn, replaceSecurityGroupsOnDestroy, replacementSecurityGroupIds, and 2 more.
So it looks like
new aws.lambda.Function
doesn’t return the type expected by the
eventHandler
. In the documentation, the route seems to work if the lambda is a
CallbackFunction
, but I certainly don’t want a Callback Function as the lambda because the lambda code is coming from Docker, and involves many dependencies, etc.. Any idea?
m

miniature-musician-31262

06/05/2023, 9:17 PM
Right, I think the types changed here with the 1.0 release. Did you know you can use the
classic
namespace to continue using the previous behavior? For example, this might work for you:
Copy code
import * as awsx from "@pulumi/awsx";

const api = new awsx.classic.apigateway.API("api", {
    routes: [
        { 
            path: "/route", 
            method: "GET", 
            eventHandler: someCallbackOrLambdaFunction,
        },
    ]
});
s

salmon-thailand-93496

06/06/2023, 12:23 AM
Thank you so much for replying! I can try that, but I’m a little worried that even if that works, that I’m somehow resisting the spirit of the times. Is the expectation that API Gateways no longer support full on Lambda Functions?
This feels to me almost the same as downgrading to the older version of Pulumi
Why would it be the case that the latest version not support lambda function types in the eventHandler?
m

miniature-musician-31262

06/06/2023, 12:36 AM
That's understandable, yeah -- although it could just be that this functionality just isn't supported in 1.0 yet. I'll ask around and see if I can get you an answer. Meantime, I went ahead and put together a full example, just so you have something "known working" to refer to (and to work through it myself, as I hadn't run into it yet!): https://github.com/cnunciato/aws-lambda-with-container-image
s

salmon-thailand-93496

06/06/2023, 12:41 AM
Oh my god. You’re incredible.
Just stepped out but I’ll test it as soon as I get back 🙌
m

miniature-musician-31262

06/06/2023, 12:41 AM
Oh, wait -- it may actually work!
I'll update my example, but I seem to be able to to use
apigateway.RestAPI
as well. Lemme doublecheck.
Yeah, that totally works! I've updated the program to drop
awsx.classic
and use
apigateway.RestAPI
. Seems fine. 🙂
s

salmon-thailand-93496

06/06/2023, 2:17 AM
Just got back. Will test now 🙏
Jesus christ. It was a version error for one of the dependencies
Wow
Thank you
g

glamorous-wolf-31414

06/09/2023, 5:38 PM
Great resources ,I'm checking and I found this error , Anyone with a similar error?
Copy code
Dockerfile:1
    --------------------
       1 | >>> FROM public.ecr.aws/lambda/nodejs:18
       2 |
       3 |     # Assumes your function is named "app.js", and there is a package.json file in the app directory
    --------------------
    ERROR: failed to solve: public.ecr.aws/lambda/nodejs:18: pulling from host public.ecr.aws failed with status code [manifests 18]: 403 Forbidden
I am login in ECR
I resolved the error with ECR but , I have the same original error :
Copy code
aws:apigateway:RestApi (api):
    error: 1 error occurred:
        * creating urn:pulumi:mimic-pul-cont::container-with-api-gateway::aws-apigateway:index:RestAPI$aws:apigateway/restApi:RestApi::api: 1 error occurred:
        * error creating API Gateway specification: BadRequestException: Errors found during import:
        Unable to put integration on 'GET' for resource at path '/route': Invalid ARN specified in the request
Thanks.
4 Views