[{"data":1,"prerenderedAt":39},["ShallowReactive",2],{"snippet-lambda-function-invoke-vpc-lattice-service":3},{"id":4,"title":5,"contributors":6,"description":8,"extension":9,"gitHub":10,"introBox":13,"languages":17,"meta":19,"resources":20,"services":21,"snippets":24,"stem":35,"tags":36,"type":37,"__hash__":38},"snippets\u002Fsnippets\u002Flambda-function-invoke-vpc-lattice-service.json","Invoke a VPC Lattice service with AWS Lambda",[7],"content\u002Fcontributors\u002Fjosh-kahn.json","This snippet invokes a VPC Lattice service that requires signing using SigV4. Signing requirement is based on the service and\u002For service network auth policy.","json",{"template":11},{"repoURL":12},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-snippets\u002Ftree\u002Fmain\u002Flambda-function-invoke-vpc-lattice-service",{"headline":14,"text":15},"How it works",[16],"After retrieving access key and other credentials from environment, sign the request for VPC Lattice services. In this snippet, we use the open source axios library to send the request to the service, but other methods for sending HTTP requests are also applicable. Setting the unsigned-payload header is currently required for VPC Lattice.",[18],"TypeScript",{},null,[22,23],"lambda-event-functions","vpc-lattice",[25],{"title":26,"codeTabs":27},"Runtimes",[28],{"id":18,"title":29,"description":30,"snippets":31},"Copy the code into your Lambda function","Follow the AWS Lambda instructions for packaging with dependencies, and uploading in .zip format.",[32],{"language":33,"code":34},"ts","import { SignatureV4 } from \"@aws-sdk\u002Fsignature-v4\";\nimport { Sha256 } from \"@aws-crypto\u002Fsha256-js\";\nimport axios from \"axios\";\n\nconst endpointUrl = new URL(VPC_LATTICE_SERVICE_ENDPOINT);\nconst sigv4 = new SignatureV4({\n    service: \"vpc-lattice-svcs\",\n    region: process.env.AWS_REGION!,\n    credentials: {\n        accessKeyId: process.env.AWS_ACCESS_KEY_ID!,\n        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,\n        sessionToken: process.env.AWS_SESSION_TOKEN\n    },\n    sha256: Sha256\n});\n\nconst signedRequest = await sigv4.sign({\n    method: \"PUT\",\n    hostname: endpointUrl.host,\n    path: endpointUrl.pathname,\n    protocol: endpointUrl.protocol,\n    headers: {\n        'Content-Type': 'application\u002Fjson',\n        host: endpointUrl.hostname,\n        \u002F\u002F Include following header as VPC Lattice does not support signed payloads\n        \"x-amz-content-sha256\": \"UNSIGNED-PAYLOAD\"\n    }\n  });    \n  const { data } = await axios({\n    ...signedRequest,\n    data: {\n        \u002F\u002F some data\n    },\n    url: VPC_LATTICE_SERVICE_ENDPOINT\n  });\n","snippets\u002Flambda-function-invoke-vpc-lattice-service",[],"Integration","r2WEdPbX8GFWVXL5ryp2Naoc8ys2Bg8APiItVSNjKmk",1792665263162]