https://pulumi.com logo
#aws
Title
# aws
m

millions-furniture-75402

03/16/2022, 9:06 PM
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

stocky-restaurant-98004

03/16/2022, 9:13 PM
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

little-cartoon-10569

03/16/2022, 9:26 PM
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

millions-furniture-75402

03/17/2022, 12:10 PM
That's a good point, I'll ask more about the requirements.
21 Views