damp-lock-9822
05/24/2023, 9:02 PMUnhandled exception: Error: Invoke: Default provider for 'aws' disabled. 'aws:ec2/getAmi:getAmi' must use an explicit provider
. It appears that the provider has not been created at this point, causing the getAmi call to fail because it attempts to use a default provider (which I've disabled). Has anyone else observed behavior like this, and if so is there some sort of workaround ?little-cartoon-10569
05/24/2023, 9:37 PMprovider
opt, not the dependsOn
opt.damp-lock-9822
05/24/2023, 9:40 PMconst commonProviderArgs = {
accessKey: this.awsConfig.AWS_ACCESS_KEY,
secretKey: pulumi.secret(this.awsConfig.AWS_SECRET_KEY),
assumeRole: {
externalId: this.awsConfig.EXTERNAL_ID,
roleArn: this.awsConfig.ROLE_ARN,
},
};
const awsClassicProvider = new awsClassic.Provider("aws-classic-test", {
...commonProviderArgs,
region: 'us-east-2',
});
const awsFix = new AwsFixtureComponent(fix.baseName, fix, configuration, awsConfig, awsClassicProvider, {providers: [awsClassicProvider]});
awsFix
.initialize()
.then((fix) => {
return fix;
})
.catch((err) => {
log.error(err);
});
return awsFix;
const fixtureAmi = await aws.ec2
.getAmi({
filters: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"],
},
],
mostRecent: true,
},
{ provider: this.provider }
)
.then((invoke) => invoke.id);
little-cartoon-10569
05/24/2023, 9:51 PMDefault provider for 'aws' disabled. 'awsec2/getAmigetAmi' must use an explicit providerIf you're getting this error, then the problem is the call to
getAmi()
. Since you have disabled default providers (which is good imo), you need to pass a provider to every call to AWS. This error is saying you haven't passed the provider to the call to getAmi()
.damp-lock-9822
05/24/2023, 9:52 PMlittle-cartoon-10569
05/24/2023, 9:53 PMdamp-lock-9822
05/24/2023, 9:53 PMlittle-cartoon-10569
05/24/2023, 9:54 PMthis.provider
? Could it be null or undefined?const awsFix = new AwsFixtureComponent(fix.baseName, fix, configuration, awsConfig, awsClassicProvider, {providers: [awsClassicProvider]});
The question here is: ?!?.then((invoke) => invoke.id);
damp-lock-9822
05/24/2023, 10:03 PM.then((invoke) => invoke.id)
I pulled from a pulumi template (https://github.com/pulumi/templates/blob/master/vm-aws-typescript/index.ts)little-cartoon-10569
05/24/2023, 10:09 PMgetAmiOutput()
. You can now use getAmiOutput(...).id
, which is more idiomatic. Also, you might store the AMI object in the variable (since that's more flexible) and get the id only when you need it (passing it into the EC2 constructor).provider
or providers
opts.damp-lock-9822
05/24/2023, 10:15 PMpulumi.all([awsClassicProvider]).apply(([awsProvider]) => {
const awsFix = new AwsFixtureComponent(fix.baseName, fix, {provider: awsProvider});
awsFix
.initialize()
.then((fix) => {
return fix;
})
.catch((err) => {
log.error(err);
});
return awsFix;
});
export class AwsFixtureComponent extends pulumi.ComponentResource {
public readonly fixture: AwsFixture;
public readonly provider: aws.Provider;
public readonly opts: pulumi.ComponentResourceOptions | undefined;
constructor(name: string, fixture: AwsFixture, opts?: pulumi.ComponentResourceOptions) {
super("fixtures:awsFixture", name, {}, opts);
this.fixture = fixture;
this.provider = this.opts?.provider as aws.Provider;
this.opts=opts;
}
little-cartoon-10569
05/24/2023, 10:27 PMdamp-lock-9822
05/24/2023, 10:27 PMlittle-cartoon-10569
05/24/2023, 10:28 PMthis.provider = this.opts?.provider as aws.Provider;
You're not detecting a missing provider.?
with !
, see where it's undefined.const provider: aws.Provider;
. That'll barf sooner, too.damp-lock-9822
05/24/2023, 10:34 PM?
there, it was undefined twice before being definedprovider
and opts
right before making the getAmi call)!
it fails in the constructor ('trying to read properties of undefined')little-cartoon-10569
05/24/2023, 10:41 PMdamp-lock-9822
05/24/2023, 11:25 PMlittle-cartoon-10569
05/24/2023, 11:33 PM