Hi.. I am trying to run a piece of code to create ...
# typescript
l
Hi.. I am trying to run a piece of code to create a group when account id of aws is xxx and i get an error on my ci saying
infra/groups.ts(6,14): error TS2322: Type 'Promise<string>' is not assignable to type 'string'.
here is the code
Copy code
const current = aws.getCallerIdentity({});
export const accountId: string = current.then(current => current.accountId);

if (accountId == "xxx") { 

const devops = new aws.iam.Group("devops", {
    name: "devops-users",
    path: "/",
});

}
s
Like the error message says,
accountId
is a
Promise<string>
so you can't so a comparison with a
string
in your
if
. You'll need to do this comparison in a context where the promise is unwrapped, either within a
.then
or after the variable is `await`ed
1
l
Often the best thing to do is to avoid this sort of issue. For example, perhaps you can infer whether or not to create the group from the stack instead of from the caller identity?
pulumi.getStack()
returns a simple string.
👍 2