trying to upload a list of files to S3, then save ...
# typescript
e
trying to upload a list of files to S3, then save the arns of those objects to a list that I can pass later in my program. Anyone know of an elegant way to do this?
b
hang on, let me throw an example together
e
you would be a hero in my eyes!
FYI..here is my code that I tried but not working
Copy code
const objectIds = [];
fs.readdir('components', (err, files) => {
	if (err) {
		return console.log('Unable to scan directory:' + err);
	}
	files.forEach((file) => {
		const fileName = file.split(".");
		const filePath = require("path").join('components', file)
		// Upload File to S3
		const componentObject = new aws.s3.BucketObject(`${config.name}-${fileName[0]}-object`, {
			key: file,
			source: new pulumi.asset.FileAsset(filePath),
			bucket: bucket.id
		});

		objectIds.push({
			objectId: componentObject.id
	});
});
b
what error are you getting?
e
no error, the array is just empty
so I’m sure I’m not handling promises properly (which I’ve always struggled to do)
b
I thought I had done this before but apparently not with the ids, @white-balloon-205 don't suppose you could help here?
oh wait, yes I have, incoming!
e
🕺
b
this works for me: https://github.com/jaxxstorm/pulumi-examples/blob/master/typescript/aws/s3/index.ts you need to make sure the
objectIds
type is correct
I've used a map here, but a for loop should work the same
e
going to give it a shot, thanks!
I get this as my output of the ID
Copy code
OutputImpl {
      __pulumiOutput: true,
      resources: [Function (anonymous)],
      allResources: [Function (anonymous)],
      isKnown: Promise { <pending> },
      isSecret: Promise { <pending> },
      promise: [Function (anonymous)],
      toString: [Function (anonymous)],
      toJSON: [Function (anonymous)]
    }
b
hey, did you get this figured out?
e
Not really. I can’t out how to reference the array later in my code. It’s always empty or undefined
Copy code
export let objectIds: pulumi.Output<string>[] = []

const objects = ["installSsm.yml"].map((name) => {
	let obj = new aws.s3.BucketObject(name, {
		bucket: bucket.id,
		source: new pulumi.asset.FileAsset(`./components/${name}`),
	})
	objectIds.push(obj.id)
	//console.log(obj.id)
	
})

console.log(objectIds)
I just don’t know how to print that objectIds promise to show the real contents instead of the
OutputImpl {….
and then assign that to a parameter later
b
@elegant-crayon-4967 you can't print it outside an apply,
console.log
won't work because it's asynchronously resolved. With the export, did it show you the values?
e
I can see the values when I’m inside arrow function
so how would I use the
.apply
agains the array?
b
what do you actually want to do with the values? it'll help figuring out the best way to use them
e
I’ll shoot you a DM