Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Timeout from SAM Template #626

Merged
merged 3 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the "aws-vscode-tools" extension will be documented in th
## NEXT (Developer Preview)

* Local Run/Debug now honors MemorySize values from SAM Template file (#509)
* Local Run/Debug now honors Timeout values from SAM Template file (#510)
* Fixed issue preventing users from connecting with assumed roles (#620)

## 0.2.0 (Developer Preview)
Expand Down
10 changes: 7 additions & 3 deletions src/shared/codelens/localLambdaRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,23 @@ export async function makeInputTemplate(params: {
properties?: CloudFormation.ResourceProperties
runtime: string
}): Promise<string> {
const newTemplate = new SamTemplateGenerator()
let newTemplate = new SamTemplateGenerator()
.withFunctionHandler(params.relativeFunctionHandler)
.withResourceName(TEMPLATE_RESOURCE_NAME)
.withRuntime(params.runtime)
.withCodeUri(params.codeDir)

if (params.properties) {
if (params.properties.Environment) {
newTemplate.withEnvironment(params.properties.Environment)
newTemplate = newTemplate.withEnvironment(params.properties.Environment)
}

if (params.properties.MemorySize) {
newTemplate.withMemorySize(params.properties.MemorySize)
newTemplate = newTemplate.withMemorySize(params.properties.MemorySize)
}

if (params.properties.Timeout) {
newTemplate = newTemplate.withTimeout(params.properties.Timeout)
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/shared/templates/sam/samTemplateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export class SamTemplateGenerator {
return this
}

public withTimeout(timeout: number): SamTemplateGenerator {
this.properties.Timeout = timeout

return this
}

public withEnvironment(env: CloudFormation.Environment): SamTemplateGenerator {
this.properties.Environment = env

Expand Down
3 changes: 3 additions & 0 deletions src/test/templates/sam/samTemplateGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('SamTemplateGenerator', () => {
const sampleFunctionHandlerValue: string = 'sampleFunctionHandler'
const sampleResourceNameValue: string = 'sampleResourceName'
const sampleMemorySize: number = 256
const sampleTimeout: number = 321
const sampleRuntimeValue: string = 'sampleRuntime'
const sampleEnvironment: CloudFormation.Environment = {
Variables: {
Expand All @@ -43,6 +44,7 @@ describe('SamTemplateGenerator', () => {
.withRuntime(sampleRuntimeValue)
.withResourceName(sampleResourceNameValue)
.withMemorySize(sampleMemorySize)
.withTimeout(sampleTimeout)
.withEnvironment(sampleEnvironment)
.generate(templateFilename)

Expand All @@ -57,6 +59,7 @@ describe('SamTemplateGenerator', () => {
assert.strictEqual(resource!.Properties!.CodeUri, sampleCodeUriValue)
assert.strictEqual(resource!.Properties!.Handler, sampleFunctionHandlerValue)
assert.strictEqual(resource!.Properties!.MemorySize, sampleMemorySize)
assert.strictEqual(resource!.Properties!.Timeout, sampleTimeout)
assert.strictEqual(resource!.Properties!.Runtime, sampleRuntimeValue)
assert.deepStrictEqual(resource!.Properties!.Environment, sampleEnvironment)
})
Expand Down