/
index.ts
72 lines (67 loc) · 2.09 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
import * as aws from "@pulumi/aws";
let music = new aws.dynamodb.Table("music", {
attributes: [
{ name: "Album", type: "S" },
{ name: "Artist", type: "S" },
{ name: "NumberOfSongs", type: "N" },
{ name: "Sales", type: "N" },
],
hashKey: "Album",
rangeKey: "Artist",
readCapacity: 1,
writeCapacity: 1,
globalSecondaryIndexes: [
{
name: "myGSI",
hashKey: "Sales",
rangeKey: "Artist",
readCapacity: 1,
writeCapacity: 1,
nonKeyAttributes: ["NumberOfSongs", "Album"],
projectionType: "INCLUDE",
},
{
name: "myGSI2",
hashKey: "NumberOfSongs",
rangeKey: "Sales",
nonKeyAttributes: ["Album", "Artist"],
projectionType: "INCLUDE",
readCapacity: 2,
writeCapacity: 2,
},
],
});
let hello = "Hello, world!";
let lambda = new aws.serverless.Function(
"mylambda",
{ policies: [aws.iam.AWSLambdaFullAccess] },
(event, context, callback) => {
console.log("Music table hash key is: " + music.hashKey);
console.log("Invoked function: " + context.invokedFunctionArn);
callback(null, {
statusCode: 200,
body: hello + "\n\nSucceeed with " + context.getRemainingTimeInMillis() + "ms remaining.\n",
});
},
);
// Validate that 'require'd packages are captured correctly.
function getContentType() {
let mime = require('mime-types');
return mime.contentType(".js");
}
const testFunc = new aws.serverless.Function("f", {
policies: [aws.iam.AWSLambdaFullAccess],
includePaths: ['./Pulumi.yaml'],
includePackages: ['body-parser'],
}, async (ev, ctx, cb) => {
var aws = await import('aws-sdk');
var express = await import('express');
var os = require('os');
// TODO[pulumi/pulumi#463] Its reasonable to expect that `./other` would work here, but it currently does not. For
// now, validate that the approach that does currently work will serialize the dependencies correctly.
var answer = require('./bin/other').answer;
console.log(answer);
getContentType();
});
exports.functionARN = testFunc.lambda.arn;