Skip to content

Commit 8cb363e

Browse files
authored
Add s3 bucket/prefix flags (#20)
* Add s3 bucket/prefix flags * add template support too * tweak docs
1 parent 2683aae commit 8cb363e

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ _Options:_
4343
`-t, --template`: Path to a SAM template. Defaults to `sam.(json|yaml)` in the current directory.
4444
`-e, --environment`: An environment name to deploy. Defaults to "development".
4545
`-p, --parameters`: A list of parameters to override in your template.
46-
`-s, --stack-name`: Option to override the auto-generated environment stack name.
47-
48-
sammie will automatically create an s3 bucket to upload your code. To change this to a different bucket, change `bucketName` in your `sam.json` template.
46+
`-s, --stack-name`: Option to override the auto-generated environment stack name.
47+
`--s3-bucket`: S3 bucket where code is uploaded. Defaults to Parameters.bucketName in template.
48+
`--s3-prefix`: S3 path prefix added to the packaged code file.
4949

5050
---
5151

src/commands/package.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ module.exports = async function packageProject(input) {
6060
const environment = input.environment || (parameters.environment && parameters.environment.Default) || 'development'
6161
const templatePathEnvMerged = await mergeEnvTemplate(templatePath, templateJson, environment)
6262
const templatePathPackaged = filePathWithSuffix(templatePath, '-packaged')
63-
const bucketName = parameters.bucketName.Default
63+
const bucketName = input['s3-bucket'] || (parameters.bucketName && parameters.bucketName.Default)
64+
const bucketPrefix = input['s3-prefix'] || (parameters.s3Prefix && parameters.s3Prefix.Default)
6465
const command =
6566
`aws cloudformation package ` +
6667
`--template-file ${templatePathEnvMerged || templatePath} ` +
6768
`--output-template-file ${templatePathPackaged} ` +
68-
`--s3-bucket ${bucketName} ` +
69-
`${templateExt === '.json' ? '--use-json' : ''}`
69+
`--s3-bucket ${bucketName}` +
70+
`${bucketPrefix ? ' --s3-prefix ' + bucketPrefix : ''}` +
71+
`${templateExt === '.json' ? ' --use-json' : ''}`
7072

7173
checkCliVersion()
7274
await createS3Bucket(bucketName)

src/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,44 @@ cli.version(packageJson.version)
1818
cli
1919
.command('init <name>')
2020
.describe('Initialize a project with a <name>')
21-
.option('-y, --yaml', 'Generate yaml for SAM template. Defaults to json, because javascript.')
21+
.option('-y, --yaml', 'Generate yaml for SAM template. Defaults to json, because javascript')
2222
.example('init my-app')
2323
.action(init)
2424

2525
cli
2626
.command('deploy')
2727
.describe('Deploy a SAM project')
28-
.option('-t, --template', 'Path to a SAM template. Defaults to `sam.(json|yaml)` in the current directory.')
29-
.option('-e, --environment', 'An environment name to deploy. Defaults to "development".')
28+
.option('-t, --template', 'Path to a SAM template. Defaults to `sam.(json|yaml)` in the current directory')
29+
.option('-e, --environment', 'An environment name to deploy. Defaults to "development"')
3030
.option('-p, --parameters', 'A list of parameters to override in your template.')
31-
.option('-s, --stack-name', 'Option to override the auto-generated environment stack name.')
31+
.option('-s, --stack-name', 'Option to override the auto-generated environment stack name')
32+
.option('--s3-bucket', 'S3 bucket where code is uploaded. Defaults to Parameters.bucketName in template')
33+
.option('--s3-prefix', 'S3 path prefix added to the packaged code file')
34+
.option('--capabilities', 'See `aws cloudformation deploy`. Defaults to CAPABILITY_IAM')
3235
.example('deploy')
3336
.example('deploy --template ./configs/sam.json --environment production --parameters key1=val1 key2=val2')
3437
.action(deploy)
3538

39+
// ---------------------------------------------------------------------
40+
// "Private" i.e. not promoting in README to keep the project focused.
41+
// Still discoverable via --help
42+
// ---------------------------------------------------------------------
43+
3644
cli
3745
.command('validate')
38-
.describe('Validate a SAM template [private - runs on `deploy`]')
46+
.describe('[private] Validate a SAM template')
3947
.option('-t, --template', 'Path to a SAM template. Defaults to `sam.(json|yaml)` in the current directory')
4048
.example('validate')
4149
.example('validate --template ./config/sam.json')
4250
.action(validate)
4351

4452
cli
4553
.command('package')
46-
.describe('Package & upload code [private - runs on `deploy`]')
54+
.describe('[private] Package & upload code')
4755
.option('-t, --template', 'Path to a SAM template. Defaults to `sam.(json|yaml)` in the current directory')
48-
.option('-e, --environment', 'An environment name to package. Defaults to "development".')
56+
.option('-e, --environment', 'An environment name to package. Defaults to "development"')
57+
.option('--s3-bucket', 'S3 bucket where code is uploaded. Defaults to Parameters.bucketName in template')
58+
.option('--s3-prefix', 'S3 path prefix added to the packaged code file')
4959
.example('package')
5060
.example('package --template ./config/sam.json --environment production')
5161
.action(packageProject)

0 commit comments

Comments
 (0)