forked from erwinverdonk/aws-cfn-stack-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·64 lines (55 loc) · 1.55 KB
/
index.js
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
#!/usr/bin/env node
const argv = require('minimist')(process.argv.slice(2));
const pjson = require(__dirname + '/package.json');
process.env.AWS_DEFAULT_REGION = argv.region || 'us-east-1';
process.env.AWS_REGION = process.env.AWS_DEFAULT_REGION
if(!argv['bucket-name']){
console.error('No "bucket-name" parameter provided as destination for the Lambda package.');
process.exit();
}
const run = () => {
const AwsLambdaUploadDeploy = require(
'@erwinverdonk/aws-lambda-upload-deploy'
).AwsLambdaUploadDeploy;
const functionName = 'AwsCfnStackResource';
AwsLambdaUploadDeploy({
functionName,
sourcePath: `${__dirname}/dist`,
version: pjson.version,
s3: {
bucketName: `${argv['bucket-name']}-${process.env.AWS_REGION}`
},
settings: {
runtime: 'nodejs8.10',
memory: 128,
timeout: 300,
permissions: [
{
effect: 'Allow',
action: ['*'],
resource: ['*']
}
]
}
})
.start();
}
// When a Role Arn is provided we try to assume the role before proceeding.
if(argv['role-arn']){
const AWS = require('aws-sdk');
const assumeRole = require('aws-assume-role').assumeRole;
assumeRole({
roleArn: argv['role-arn']
})
.then(_ => {
// Setting temporary credentials as the credentials to use.
process.env.AWS_ACCESS_KEY_ID = _.accessKeyId;
process.env.AWS_SECRET_ACCESS_KEY = _.secretAccessKey;
process.env.AWS_SESSION_TOKEN = _.sessionToken;
AWS.config = new AWS.Config();
// Run the deploy logic
run();
});
} else {
run();
}