What is the "Pulumi native" way to handle getParam...
# aws
m
What is the "Pulumi native" way to handle getParameter when one does not exist? I can handle it with the SDK:
Copy code
const ssmClient = new aws.sdk.SSM();
ssmClient.getParameter({ Name: "does-not-exist" }, function (err: any, data: any) {
  if (err) {
    new aws.ssm.Parameter("foo", {
      type: "String",
      value: "bar",
    });
  }
});
but it errors when I try to handle one not existing with getParameter:
Copy code
pulumi.output(
    aws.ssm.getParameter({
      name: "does-not-exist",
    }),
  ) ||
  new aws.ssm.Parameter("foo", {
    type: "String",
    value: "bar",
  });
Copy code
Error: invocation of aws:ssm/getParameter:getParameter returned an error: invoking aws:ssm/getParameter:getParameter: 1 error occurred:
        * Error describing SSM parameter (doesn-not-exist): ParameterNotFound:
s
You might be able to use getParametersByPath with a very specific path: https://www.pulumi.com/registry/packages/aws/api-docs/ssm/getparametersbypath/
And then check for the length of
arns
in the returned value.
l
Seems like not the Pulumi way? As a rule, if you ever intend to manage the Parameter, then you should always manage the parameter.
It would be better to manually check if the parameter exists once, and import it if it does.
m
That's a good point, I'll ask more about the requirements.