Skip to content

Commit

Permalink
parse from sls info command
Browse files Browse the repository at this point in the history
  • Loading branch information
ebisbe committed Jul 12, 2024
1 parent a8993a4 commit 28f0712
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.serverless
coverage
coverage
.env.e2e
44 changes: 16 additions & 28 deletions post-deploy.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
import { execSync } from "child_process";
import { writeFileSync } from "fs";
import { parseArgs } from "util";

const args = process.argv;
const options = {
name: {
type: "string",
},
region: {
type: "string",
},
};
const { values } = parseArgs({
args,
options,
allowPositionals: true,
});
try {
// Execute `sls info --verbose` and capture output
const output = execSync("pnpm sls info --verbose", { encoding: "utf-8" });

// Execute the AWS CLI command to get the CloudFormation outputs
const output = execSync(
`aws cloudformation describe-stacks --stack-name ${values.name} --region ${values.region} --query "Stacks[0].Outputs" --output json`,
);
// Extract the API Gateway URL from the output
const match = output.match(/HttpApiUrl: (.*)/);
if (match && match.length > 1) {
const apiGatewayUrl = match[1].trim();

// Parse the output
const outputs = JSON.parse(output);
// Write the URL to the .env file
writeFileSync(".env.e2e", `API_GATEWAY_URL=${apiGatewayUrl}\n`);

// Find the API Gateway URL
const apiGatewayUrl = outputs.find(
(o) => o.OutputKey === "HttpApiUrl",
).OutputValue;

// Write the URL to the .env file
writeFileSync(".env.e2e", `API_GATEWAY_URL=${apiGatewayUrl}\n`);
console.log(`API Gateway URL: ${apiGatewayUrl}`);
} else {
console.error("Failed to extract API Gateway URL from `sls info` output.");
}
} catch (error) {
console.error("Error executing `sls info` command:", error);
}

0 comments on commit 28f0712

Please sign in to comment.