https://pulumi.com logo
Title
c

colossal-battery-24701

07/05/2021, 11:03 AM
Hey guys, I am trying to add env variables from stack config to lambda API in API Gateway with awsx. But I am getting error
Type 'Output<string> | undefined' is not assignable to type 'Input<string>'.
How can I add these variables neatly? This example shows only one API and few variable but in actual code, I have many routes and 20+ env variable. Any help is appreciated
export const apiGateway = new awsx.apigateway.API('retool-lambda-api-gw', {
    routes: [
        {
            path: '/oc/d-sup',
            authorizers: authorizerAPI,
            method: 'POST',
            eventHandler: new aws.lambda.CallbackFunction('retool-lambda-delete-supporter', {
                callback: async (event: awsx.apigateway.Request) => {
                    return routes.deleteSupporterHandler(event);
                },
                environment: {
                    variables: {
                        DB_HOST: config.getSecret('DB_HOST'), // this and the below vars throw error
                        DB_USER: config.getSecret('DB_USER'),
                        DB_PASSWORD: config.getSecret('DB_PASSWORD'),
                        DB_NAME: config.getSecret('DB_NAME'),
                    }
                },
                role: role,
                vpcConfig: {
                    subnetIds: [awsNetworkingEnvVariables.SUBNET_ID],
                    securityGroupIds: [lambdaSecurityGroup.id],
                }
            }),
        },
    ],
});
c

curved-pharmacist-41509

07/05/2021, 12:28 PM
If you use
requireSecret
rather than
getSecret
it should work