hi all, I seem to be getting kernel panic whenever...
# getting-started
m
hi all, I seem to be getting kernel panic whenever I try to use an s3 website endpoint as an argument for a CF cdn:
Copy code
const prodRedirectBucket = new aws.s3.Bucket(pre('redirect'), {
    website: {
        redirectAllRequestsTo: '<https://www.pickmybrain.world>',
		
    },
	acl: "public-read"
}, { provider: usEast1 });

const distribution = new aws.cloudfront.Distribution(pre('redirectCdn'), {
    origins: prodRedirectBucket.websiteEndpoint.apply(endpoint => {
		return [{
			domainName: endpoint,
			originId: prodRedirectBucket.arn,
		}]
	}),
^ this produces:
Copy code
panic: interface conversion: interface {} is nil, not map[string]interface {}
    goroutine 83 [running]:
the following:
Copy code
const distribution = new aws.cloudfront.Distribution(pre('redirectCdn'), {
    origins: [{
			domainName: prodRedirectBucket.websiteEndpoint,
			originId: prodRedirectBucket.arn,
		}],
doesn't work. If I add dependsOn: bucket to the CDN, i get kernel panic again. It resolves successfully in const export = at the bottom.
I've tested setting the CDN to the website endpoint in AWS Console and it works just fine
the other error I get with a diff variation of the above is:
Copy code
panic: interface conversion: interface {} is nil, not map[string]interface {}
Also, in pulumi preview, the following:
Copy code
const distribution = new aws.cloudfront.Distribution(pre('redirectCdn'), {
    origins: prodRedirectBucket.websiteEndpoint.apply(endpoint => {
		console.dir(`ENDPOINT ${endpoint}`)
		return [{
			domainName: endpoint,
			originId: prodRedirectBucket.arn,
		}]
resolves correctly. but when trying pulumi up with the same code, it bombs
i
Hi @magnificent-soccer-44287 Would you please file an issue https://github.com/pulumi/pulumi/issues/new/choose to track this potential bug you've hit?
a
Any luck on this?
m
hey @adorable-receptionist-25731, this was a while ago. If i remember correctly, for some odd reason, this caused a kernel panic:
Copy code
pulumi.interpolate(`var`);
while this did not:
Copy code
pulumi.interpolate`var`;
it could have a lot to do with my local, or any other factors - as most bugs do. Are you running into a similar issue?
a
Yes still getting the same issue 😅 Thanks @magnificent-soccer-44287 let me give that a try..
m
^ Any luck?
a
Still can't concatenate OutputStrings with
interpolate
.
apply
seems to be the only solution..
m
Can you share your code by chance?
i
Here's a full typescript example:
Copy code
import * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";

// Create an S3 bucket and enable it as a website
const siteBucket = new aws.s3.Bucket("siteBucket", {
    website: {
        indexDocument: "index.html",
    },
});

// Create a CloudFront origin access identity to give CloudFront access to the S3 bucket
const originAccessId = new aws.cloudfront.OriginAccessIdentity("originAccessId");

// Create a CloudFront distribution with the S3 bucket as an origin
const cdn = new aws.cloudfront.Distribution("cdn", {
    origins: [{
        domainName: siteBucket.bucketRegionalDomainName,
        originId: siteBucket.arn,
        s3OriginConfig: {
            originAccessIdentity: originAccessId.cloudfrontAccessIdentityPath,
        },
    }],
    enabled: true,
    defaultCacheBehavior: {
        targetOriginId: siteBucket.arn,
        viewerProtocolPolicy: "redirect-to-https",
        allowedMethods: ["GET", "HEAD", "OPTIONS"],
        cachedMethods: ["GET", "HEAD"],
        defaultTtl: 3600,
        maxTtl: 86400,
        minTtl: 0,
        forwardedValues: {
            queryString: false,
            cookies: { forward: "none" },
        },
    },
    restrictions: {
        geoRestriction: {
            restrictionType: "none",
        },
    },
    viewerCertificate: {
        cloudfrontDefaultCertificate: true,
    },
});

// Export the name of the bucket and the CDN URL
export const bucketName = siteBucket.id;
export const cdnURL = cdn.domainName;

// Export a variable with the interpolated string
export const interpol = pulumi.interpolate`The bucket name is ${siteBucket.id} and the CDN URL is ${cdn.domainName}`;
Copy code
❯ AWS_PROFILE=work pulumi up --yes
Previewing update (dev)

View in Browser (Ctrl+O): <https://app.pulumi.com/diana-pulumi-corp/interpol/dev/previews/0781b8a1-f08d-47c7-977c-696b69415444>

     Type                            Name          Plan       
     pulumi:pulumi:Stack             interpol-dev             
 +   └─ aws:cloudfront:Distribution  cdn           create     

Outputs:
  + bucketName: "sitebucket-7783c10"
  + cdnURL    : output<string>
  + interpol  : output<string>

Resources:
    + 1 to create
    3 unchanged

Updating (dev)

View in Browser (Ctrl+O): <https://app.pulumi.com/diana-pulumi-corp/interpol/dev/updates/2>

     Type                            Name          Status             
     pulumi:pulumi:Stack             interpol-dev                     
 +   └─ aws:cloudfront:Distribution  cdn           created (537s)     

Outputs:
  + bucketName: "sitebucket-7783c10"
  + cdnURL    : "<http://d2i8q82xz58e4h.cloudfront.net|d2i8q82xz58e4h.cloudfront.net>"
  + interpol  : "The bucket name is sitebucket-7783c10 and the CDN URL is <http://d2i8q82xz58e4h.cloudfront.net|d2i8q82xz58e4h.cloudfront.net>"

Resources:
    + 1 created
    3 unchanged

Duration: 9m3s
a
@magnificent-soccer-44287 so I was getting the issue when concatenating strings with interpolate. Had to resort to this
Copy code
const policyCondition = callerIdentity.accountId.apply(accountId => {
    return bucket.id.apply(bucketId => {
      return {
        sourceArn: `arn:aws:cloudfront::${accountId}:distribution/${bucketId}`,
      };
    });
  });
m
a lot of your problems will go away if you leverage .all
Copy code
pulumi.all([callerIdentity.accountId,bucket.id]).apply(([accountId, bucketId]) => {
    return {
        sourceArn: `arn:aws:cloudfront::${accountId}:distribution/${bucketId}`,
      };
})
try that 🙂
its basically a .map(x => x.apply) which takes the .all args and maps it to the .apply args, but what you are .apply mapping is the args as arrays via spread syntax
lmk if that helps/works!
a
Like a charm! thanks @magnificent-soccer-44287 💪