Simple AWS Lambda to verify the network connectivity when using a private VPC
doesn't require any dependencies,
so you can create a lambda,
configure the VPC,
then upload the index.js
const https = require("https");
async function post() {
const options = {
hostname: "google.com",
port: 443,
path: "/",
method: "GET",
};
const p = new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
res.setEncoding("utf8");
let responseBody = "";
res.on("data", (chunk) => {
responseBody += chunk;
});
res.on("end", () => {
resolve(responseBody);
});
});
req.on("error", (err) => {
reject(err);
});
req.end();
});
try {
const response = await p;
console.log(response);
return response;
} catch (e) {
console.error(e.message);
throw e;
}
}
exports.handler = async (event) => {
await post();
};
Then you can start the lambda using the CLI or the UI. The easiest and quick way is using the UI with the test feature.
Get the ENI:
aws lambda list-functions --query="Functions[].{VpcConfig:{VpcId: VpcConfig.VpcId}}"
Get VPCs:
aws ec2 describe-vpcs --query="Vpcs[].{CidrBlock: CidrBlock, VpcId: VpcId}"