Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
943 B
8
Indexable
Never
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";

const ssmClient = new SSMClient({});

export const handler = async () => {
  try {
    const parameterName = process.env.SSM_PARAMETER_NAME;
    if (!parameterName) {
      throw new Error("SSM_PARAMETER_NAME environment variable is not set");
    }

    const command = new GetParameterCommand({
      Name: parameterName,
      WithDecryption: true,
    });
    const { Parameter } = await ssmClient.send(command);

    return {
      statusCode: 200,
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        message: "Hello World",
        parameterValue: Parameter?.Value,
      }),
    };
  } catch (error) {
    console.error(error);
    return {
      statusCode: 500,
      body: JSON.stringify({
        error: error instanceof Error ? error.message : "Unknown error",
      }),
    };
  }
};
Leave a Comment