Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add-support-for-m…
Browse files Browse the repository at this point in the history
…sk-as-event-trigger
  • Loading branch information
pgrzesik committed Sep 1, 2020
2 parents f6419cf + 7aad819 commit a4f1d4c
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 225 deletions.
12 changes: 12 additions & 0 deletions bin/slss.js
@@ -0,0 +1,12 @@
#!/usr/bin/env node

// TODO (BREAKING): Remove this file with next major release

'use strict';

require('../lib/utils/logDeprecation')(
'SLSS_CLI_ALIAS',
'Support for "slss" command will be removed with v2.0.0. Use "sls" or "serverless" instead'
);

require('./serverless.js');
6 changes: 6 additions & 0 deletions docs/deprecations.md
Expand Up @@ -6,6 +6,12 @@ layout: Doc

# Serverless Framework Deprecations

<a name="SLSS_CLI_ALIAS"><div>&nbsp;</div></a>

## `slss` alias

Support for `slss` command will be removed with v2.0.0. Use `sls` or `serverless` instead.

<a name="AWS_FUNCTION_DESTINATIONS_ASYNC_CONFIG"><div>&nbsp;</div></a>

## AWS Lambda Function Destinations `maximumEventAge` & `maximumRetryAttempts`
Expand Down
16 changes: 16 additions & 0 deletions docs/providers/aws/events/apigateway.md
Expand Up @@ -994,6 +994,22 @@ functions:
You can then access the query string `https://example.com/dev/whatever?bar=123` by `event.foo` in the lambda function.
If you want to spread a string into multiple lines, you can use the `>` or `|` syntax, but the following strings have to be all indented with the same amount, [read more about `>` syntax](http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines).

In order to remove one of the default request templates you just need to pass it as null, as follows:

```yml
functions:
create:
handler: posts.create
events:
- http:
method: get
path: whatever
integration: lambda
request:
template:
application/x-www-form-urlencoded: null
```

#### Pass Through Behavior

[API Gateway](https://serverless.com/amazon-api-gateway/) provides multiple ways to handle requests where the Content-Type header does not match any of the specified mapping templates. When this happens, the request payload will either be passed through the integration request _without transformation_ or rejected with a `415 - Unsupported Media Type`, depending on the configuration.
Expand Down
24 changes: 11 additions & 13 deletions lib/plugins/aws/info/getStackInfo.js
Expand Up @@ -34,24 +34,22 @@ module.exports = {
if (httpApiId) {
sdkRequests.push(
(httpApiId['Fn::ImportValue']
? resolveCfImportValue(this.provider, httpApiId['Fn::ImportValue']).then(id => {
if (!id) {
throw new this.serverless.classes.Error(
`Could not resolve provider.httpApi.id parameter. Configured value: ${JSON.stringify(
httpApiId
)}`
);
}
return id;
})
? resolveCfImportValue(this.provider, httpApiId['Fn::ImportValue'])
: BbPromise.resolve(httpApiId)
)
.then(id => {
return this.provider.request('ApiGatewayV2', 'getApi', { ApiId: id });
})
.then(result => {
if (result) stackData.externalHttpApiEndpoint = result.ApiEndpoint;
})
.then(
result => {
stackData.externalHttpApiEndpoint = result.ApiEndpoint;
},
error => {
throw new this.serverless.classes.Error(
`Could not resolve provider.httpApi.id parameter. ${error.message}`
);
}
)
);
}

Expand Down
18 changes: 14 additions & 4 deletions lib/plugins/aws/info/getStackInfo.test.js
Expand Up @@ -195,15 +195,25 @@ describe('#getStackInfo()', () => {
id: 'http-api-id',
};

const describeStacksResponse = null;

describeStacksStub.resolves(describeStacksResponse);
describeStacksStub
.withArgs('CloudFormation', 'describeStacks', {
StackName: awsInfo.provider.naming.getStackName(),
})
.resolves(null);

describeStacksStub
.withArgs('ApiGatewayV2', 'getApi', {
ApiId: 'http-api-id',
})
.resolves({
ApiEndpoint: 'my-endpoint',
});

const expectedGatheredDataObj = {
info: {
functions: [],
layers: [],
endpoints: [],
endpoints: ['httpApi: my-endpoint'],
service: 'my-service',
stage: 'dev',
region: 'us-east-1',
Expand Down
81 changes: 50 additions & 31 deletions lib/plugins/aws/invokeLocal/index.js
Expand Up @@ -19,6 +19,7 @@ const dirExists = require('../../../utils/fs/dirExists');
const fileExists = require('../../../utils/fs/fileExists');
const isStandalone = require('../../../utils/isStandaloneExecutable');
const getEnsureArtifact = require('../../../utils/getEnsureArtifact');
const resolveCfImportValue = require('../utils/resolveCfImportValue');

const mkdirpAsync = BbPromise.promisify(mkdirp);

Expand Down Expand Up @@ -150,41 +151,59 @@ class AwsInvokeLocal {
}

loadEnvVars() {
const lambdaName = this.options.functionObj.name;
const memorySize =
Number(this.options.functionObj.memorySize) ||
Number(this.serverless.service.provider.memorySize) ||
1024;

const lambdaDefaultEnvVars = {
LANG: 'en_US.UTF-8',
LD_LIBRARY_PATH:
'/usr/local/lib64/node-v4.3.x/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib', // eslint-disable-line max-len
LAMBDA_TASK_ROOT: '/var/task',
LAMBDA_RUNTIME_DIR: '/var/runtime',
AWS_REGION: this.provider.getRegion(),
AWS_DEFAULT_REGION: this.provider.getRegion(),
AWS_LAMBDA_LOG_GROUP_NAME: this.provider.naming.getLogGroupName(lambdaName),
AWS_LAMBDA_LOG_STREAM_NAME: '2016/12/02/[$LATEST]f77ff5e4026c45bda9a9ebcec6bc9cad',
AWS_LAMBDA_FUNCTION_NAME: lambdaName,
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: memorySize,
AWS_LAMBDA_FUNCTION_VERSION: '$LATEST',
NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules',
};

const credentialEnvVars = this.getCredentialEnvVars();
return BbPromise.try(() => {
const lambdaName = this.options.functionObj.name;
const memorySize =
Number(this.options.functionObj.memorySize) ||
Number(this.serverless.service.provider.memorySize) ||
1024;

const lambdaDefaultEnvVars = {
LANG: 'en_US.UTF-8',
LD_LIBRARY_PATH:
'/usr/local/lib64/node-v4.3.x/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib', // eslint-disable-line max-len
LAMBDA_TASK_ROOT: '/var/task',
LAMBDA_RUNTIME_DIR: '/var/runtime',
AWS_REGION: this.provider.getRegion(),
AWS_DEFAULT_REGION: this.provider.getRegion(),
AWS_LAMBDA_LOG_GROUP_NAME: this.provider.naming.getLogGroupName(lambdaName),
AWS_LAMBDA_LOG_STREAM_NAME: '2016/12/02/[$LATEST]f77ff5e4026c45bda9a9ebcec6bc9cad',
AWS_LAMBDA_FUNCTION_NAME: lambdaName,
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: memorySize,
AWS_LAMBDA_FUNCTION_VERSION: '$LATEST',
NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules',
};

// profile override from config
const profileOverride = this.provider.getProfile();
if (profileOverride) {
lambdaDefaultEnvVars.AWS_PROFILE = profileOverride;
}
const credentialEnvVars = this.getCredentialEnvVars();

const configuredEnvVars = this.getConfiguredEnvVars();
// profile override from config
const profileOverride = this.provider.getProfile();
if (profileOverride) {
lambdaDefaultEnvVars.AWS_PROFILE = profileOverride;
}

_.merge(process.env, lambdaDefaultEnvVars, credentialEnvVars, configuredEnvVars);
const configuredEnvVars = this.getConfiguredEnvVars();

const promises = _.entries(configuredEnvVars).map(([name, value]) => {
return (value['Fn::ImportValue']
? resolveCfImportValue(this.provider, value['Fn::ImportValue'])
: BbPromise.resolve(value)
).then(
resolvedValue => {
configuredEnvVars[name] = resolvedValue;
},
error => {
throw new this.serverless.classes.Error(
`Could not resolve ${name} environment variable. ${error.message}`
);
}
);
});

return BbPromise.resolve();
return BbPromise.all(promises).then(() => {
_.merge(process.env, lambdaDefaultEnvVars, credentialEnvVars, configuredEnvVars);
});
});
}

invokeLocal() {
Expand Down
Expand Up @@ -1304,6 +1304,37 @@ describe('#compileMethods()', () => {
});
});

it('should delete the default "application/x-www-form-urlencoded" template if it\'s overriden with null', () => {
awsCompileApigEvents.validated.events = [
{
functionName: 'Second',
http: {
method: 'get',
path: 'users/list',
integration: 'AWS',
request: {
template: {
'application/x-www-form-urlencoded': null,
},
},
response: {
statusCodes: {
200: {
pattern: '',
},
},
},
},
},
];
return awsCompileApigEvents.compileMethods().then(() => {
expect(
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources
.ApiGatewayMethodUsersListGet.Properties.Integration.RequestTemplates
).to.not.have.key('application/x-www-form-urlencoded');
});
});

it('should use defined pass-through behavior', () => {
awsCompileApigEvents.validated.events = [
{
Expand Down
Expand Up @@ -209,7 +209,13 @@ module.exports = {

// set custom request templates if provided
if (http.request && typeof http.request.template === 'object') {
Object.assign(integrationRequestTemplates, http.request.template);
_.entries(http.request.template).forEach(([contentType, template]) => {
if (template === null) {
delete integrationRequestTemplates[contentType];
} else {
integrationRequestTemplates[contentType] = template;
}
});
}

return Object.keys(integrationRequestTemplates).length
Expand Down

0 comments on commit a4f1d4c

Please sign in to comment.