import * as pulumi from "@pulumi/pulumi" ; import * as aws from "@pulumi/aws" ; import * as awsx from "@pulumi/awsx" ; const config = new pulumi . Config ( "aws" ) ; const providerOpts = { provider : new aws . Provider ( "prov" , { region : < aws . Region > config . require ( "envRegion" ) } ) } ; const sg = new awsx . ec2 . SecurityGroup ( "web-sg" , { vpc : awsx . ec2 . Vpc . getDefault ( providerOpts ) , egress : [ { protocol : "-1" , fromPort : 0 , toPort : 0 , cidrBlocks : [ "0.0.0.0/0" ] } ] , } , providerOpts ) ; const alb = new awsx . elasticloadbalancingv2 . ApplicationLoadBalancer ( "web-traffic" , { external : true , securityGroups : [ sg ] } , providerOpts ) ; const listener = alb . createTargetGroup ( "web-target-group" , { targetType : "lambda" , port : 80 } ) . createListener ( "web-listener" , { port : 80 } ) ; alb . attachTarget ( "lambda-target" , async ( request ) => { console . log ( JSON . stringify ( request ) ) ; return { isBase64Encoded : false , statusCode : 200 , headers : { "Set-cookie" : "cookies" , "Content-Type" : "application/json" } , body : "Hello from Lambda (optional)" , } ; } ) ; export const endpoint = listener . endpoint ;