Move from object syntax to simple string syntax

This commit is contained in:
Philipp Muens 2019-02-22 13:08:46 +01:00
parent 4bd8b593b9
commit a0b9951ac2
4 changed files with 19 additions and 51 deletions

View File

@ -28,8 +28,7 @@ provider:
memorySize: 512 # optional, in MB, default is 1024
timeout: 10 # optional, in seconds, default is 6
versionFunctions: false # optional, default is true
tracingConfig: # optional, enables tracing for all functions (can be 'Active' or 'PassThrough')
mode: Active
tracingConfig: Active # optional, enables tracing for all functions (can be 'Active' or 'PassThrough')
functions:
hello:
@ -40,8 +39,7 @@ functions:
memorySize: 512 # optional, in MB, default is 1024
timeout: 10 # optional, in seconds, default is 6
reservedConcurrency: 5 # optional, reserved concurrency limit for this function. By default, AWS uses account concurrency limit
tracingConfig: # optional, overwrite, can be 'Active' or 'PassThrough'
mode: PassThrough
tracingConfig: PassThrough # optional, overwrite, can be 'Active' or 'PassThrough'
```
The `handler` property points to the file and module containing the code you want to run in your function.
@ -437,7 +435,7 @@ When storing secrets in environment variables, AWS [strongly suggests](http://do
## AWS X-Ray Tracing
You can enable [AWS X-Ray Tracing](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html) on your Lambda functions through the optional `tracingConfig` config variable in conjucntion with the `mode` property:
You can enable [AWS X-Ray Tracing](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html) on your Lambda functions through the optional `tracingConfig` config variable:
```yml
service: myService
@ -445,8 +443,7 @@ service: myService
provider:
name: aws
runtime: nodejs8.10
tracingConfig:
mode: Active
tracingConfig: Active
```
You can also set this variable on a per-function basis. This will override the provider level setting if present:
@ -455,10 +452,8 @@ You can also set this variable on a per-function basis. This will override the p
functions:
hello:
handler: handler.hello
tracingConfig:
mode: Active
tracingConfig: Active
goodbye:
handler: handler.goodbye
tracingConfig:
mode: PassThrough
tracingConfig: PassThrough
```

View File

@ -117,8 +117,7 @@ provider:
tags: # Optional service wide function tags
foo: bar
baz: qux
tracingConfig:
mode: Active # optional, can be 'Active' or 'PassThrough'
tracingConfig: Active # optional, can be 'Active' or 'PassThrough'
package: # Optional deployment packaging configuration
include: # Specify the directories and files which should be included in the deployment package
@ -165,8 +164,7 @@ functions:
individually: true # Enables individual packaging for specific function. If true you must provide package for each function. Defaults to false
layers: # An optional list Lambda Layers to use
- arn:aws:lambda:region:XXXXXX:layer:LayerName:Y # Layer Version ARN
tracingConfig:
mode: Active # optional, can be 'Active' or 'PassThrough' (overwrites the one defined on the provider level)
tracingConfig: Active # optional, can be 'Active' or 'PassThrough' (overwrites the one defined on the provider level)
events: # The Events that trigger this Function
- http: # This creates an API Gateway HTTP endpoint which can be used to trigger this function. Learn more in "events/apigateway"
path: users/create # Path for this endpoint

View File

@ -246,12 +246,12 @@ class AwsCompileFunctions {
|| this.serverless.service.provider.tracingConfig;
if (tracingConfig) {
if (tracingConfig.mode && typeof tracingConfig.mode === 'string') {
if (typeof tracingConfig === 'string') {
const iamRoleLambdaExecution = this.serverless.service.provider
.compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution;
newFunction.Properties.TracingConfig = {
Mode: tracingConfig.mode,
Mode: tracingConfig,
};
const stmt = {
@ -272,7 +272,7 @@ class AwsCompileFunctions {
);
}
} else {
const errorMessage = 'tracingConfig must provide a "mode" property as a string';
const errorMessage = 'tracingConfig requires the "mode" as a string';
throw new this.serverless.classes.Error(errorMessage);
}
}

View File

@ -1296,39 +1296,22 @@ describe('AwsCompileFunctions', () => {
.split(path.sep).pop();
});
it('should throw an error if "mode" config parameter is not provided', () => {
it('should throw an error if config paramter is not a string', () => {
awsCompileFunctions.serverless.service.functions = {
func: {
handler: 'func.function.handler',
name: 'new-service-dev-func',
tracingConfig: 'Active',
tracingConfig: 123,
},
};
return expect(awsCompileFunctions.compileFunctions())
.to.be.rejectedWith('property as a string');
});
it('should throw an error if "mode" config paramter is not a string', () => {
awsCompileFunctions.serverless.service.functions = {
func: {
handler: 'func.function.handler',
name: 'new-service-dev-func',
tracingConfig: {
mode: 123,
},
},
};
return expect(awsCompileFunctions.compileFunctions())
.to.be.rejectedWith('property as a string');
.to.be.rejectedWith('as a string');
});
it('should use a the provider wide tracingConfig config if provided', () => {
Object.assign(awsCompileFunctions.serverless.service.provider, {
tracingConfig: {
mode: 'Active',
},
tracingConfig: 'Active',
});
awsCompileFunctions.serverless.service.functions = {
@ -1371,18 +1354,14 @@ describe('AwsCompileFunctions', () => {
it('should prefer a function tracingConfig config over a provider config', () => {
Object.assign(awsCompileFunctions.serverless.service.provider, {
tracingConfig: {
mode: 'Active',
},
tracingConfig: 'Active',
});
awsCompileFunctions.serverless.service.functions = {
func1: {
handler: 'func1.function.handler',
name: 'new-service-dev-func1',
tracingConfig: {
mode: 'PassThrough',
},
tracingConfig: 'PassThrough',
},
func2: {
handler: 'func2.function.handler',
@ -1469,9 +1448,7 @@ describe('AwsCompileFunctions', () => {
func: {
handler: 'func.function.handler',
name: 'new-service-dev-func',
tracingConfig: {
mode: 'Active',
},
tracingConfig: 'Active',
},
};
@ -1527,9 +1504,7 @@ describe('AwsCompileFunctions', () => {
func: {
handler: 'func.function.handler',
name: 'new-service-dev-func',
tracingConfig: {
mode: 'Active',
},
tracingConfig: 'Active',
},
};