early-musician-41645
11/21/2018, 11:01 PMwhite-balloon-205
aws.apigateway.x.API
to simplify construction of API Gateway: https://github.com/pulumi/examples/blob/master/aws-ts-apigateway/index.ts
3. Using our @pulumi/cloud
package to do this in a cloud-neutral way: https://github.com/pulumi/examples/blob/master/cloud-js-api/index.js
I'd suggest starting with (2), and referring to (1) if you need to tweak a lot of things or want to build everything up yourself.
Note that the example in (2) uses a Lambda
provided as a callback inline, but you can also just pass a new aws.lambda.Function
you create yourself if you'd like.early-musician-41645
11/21/2018, 11:50 PMlistObjects
with @pulumi/aws
?white-balloon-205
listObjects
during deployment? Or inside of a Lambda
that runs at runtime?early-musician-41645
11/21/2018, 11:58 PMwhite-balloon-205
import * as aws from "@pulumi/aws";
let bucket = new aws.s3.Bucket("mybucket");
let object = new aws.s3.BucketObject("myobject", { bucket: bucket, key: "a", content: "hello" });
let endpoint = new aws.apigateway.x.API("hello-world", {
routes: [
{ path: "/", method: "GET", eventHandler: async (event) => {
const s3 = new aws.sdk.S3();
const objects = await s3.listObjects({ Bucket: bucket.id.get() }).promise();
return {
statusCode: 200,
body: JSON.stringify(objects),
}
},
}],
});
export let url = endpoint.url;
$ curl $(pulumi stack output url)
{"IsTruncated":false,"Marker":"","Contents":[{"Key":"a","LastModified":"2018-11-22T00:05:49.000Z","ETag":"\"5d41402abc4b2a76b9719d911017c592\"","Size":5,"StorageClass":"STANDARD","Owner":{"DisplayName":"joe","ID":"244d02f41fe32cd728a7d20986e102c9b2f626516b8cfe9477a0b7089765463f"}}],"Name":"mybucket-db4f5d2","Prefix":"","MaxKeys":1000,"CommonPrefixes":[]}
early-musician-41645
11/22/2018, 12:09 AMwhite-balloon-205
Prefix:
to `listObjects above to apply a prefix. And could compute that prefix from event.queryStringParameters
, event.body
or event.pathParameters
if needed.early-musician-41645
11/22/2018, 12:11 AMwhite-balloon-205
Instead of creating an S3 bucket, can I get an existing one?Yep -
let bucket = aws.s3.Bucket.get("mybucket", "<http://www-pulumi-com.chris.moolumi.io|www-pulumi-com.chris.moolumi.io>")
. Where the second arg is the name of the bucket.