Skip to content

Commit bf31aa9

Browse files
authored
Merge pull request #5 from gagoar/gg/addingHTTPTimeout
Adding HTTP_TIMEOUT and MAX_RETRIES options
2 parents 37635ad + c7cd416 commit bf31aa9

File tree

9 files changed

+103
-46
lines changed

9 files changed

+103
-46
lines changed

__tests__/index.spec.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { main, Props, Credentials } from '../src';
1+
import AWS from 'aws-sdk/global';
2+
import { main, Props, Credentials, ExtraOptions } from '../src';
23
import { setFailed, getInput, setOutput } from '../__mocks__/@actions/core';
34
import Lambda, { constructorMock } from '../__mocks__/aws-sdk/clients/lambda';
45

@@ -8,12 +9,12 @@ describe('invoke-aws-lambda', () => {
89
[Props.LogType]: 'None',
910
[Props.Payload]: '{"input": {value: "1"}',
1011
[Props.Qualifier]: 'production',
12+
[ExtraOptions.HTTP_TIMEOUT]: '220000',
13+
[ExtraOptions.MAX_RETRIES]: '3',
1114
[Credentials.AWS_ACCESS_KEY_ID]: 'someAccessKey',
1215
[Credentials.AWS_SECRET_ACCESS_KEY]: 'someSecretKey',
1316
REGION: 'us-west-2',
1417
};
15-
16-
1718
getInput.mockImplementation(
1819
(key: Partial<Props & Credentials & 'REGION'>) => {
1920
return mockedInput[key];
@@ -27,14 +28,18 @@ describe('invoke-aws-lambda', () => {
2728
});
2829

2930
it('runs when provided the correct input', async () => {
30-
3131
const handler = jest.fn(() => ({ response: 'ok' }));
3232

3333
Lambda.__setResponseForMethods({ invoke: handler });
3434

3535
await main();
36-
expect(getInput).toHaveBeenCalledTimes(10);
36+
expect(getInput).toHaveBeenCalledTimes(12);
3737
expect(setFailed).not.toHaveBeenCalled();
38+
expect(AWS.config.httpOptions).toMatchInlineSnapshot(`
39+
Object {
40+
"timeout": 220000,
41+
}
42+
`);
3843
expect(constructorMock.mock.calls).toMatchInlineSnapshot(`
3944
Array [
4045
Array [
@@ -45,8 +50,7 @@ describe('invoke-aws-lambda', () => {
4550
],
4651
]
4752
`);
48-
expect(handler.mock.calls).toMatchInlineSnapshot(
49-
`
53+
expect(handler.mock.calls).toMatchInlineSnapshot(`
5054
Array [
5155
Array [
5256
Object {
@@ -57,8 +61,7 @@ describe('invoke-aws-lambda', () => {
5761
},
5862
],
5963
]
60-
`
61-
);
64+
`);
6265
expect(setOutput.mock.calls).toMatchInlineSnapshot(`
6366
Array [
6467
Array [
@@ -72,14 +75,21 @@ describe('invoke-aws-lambda', () => {
7275
});
7376

7477
it('fails when lambda throws an error', async () => {
75-
const handler = jest.fn(() => { throw new Error('something went horribly wrong') });
78+
const handler = jest.fn(() => {
79+
throw new Error('something went horribly wrong');
80+
});
81+
7682
Lambda.__setResponseForMethods({ invoke: handler });
7783

7884
await main();
79-
expect(getInput).toHaveBeenCalledTimes(10);
85+
86+
expect(getInput).toHaveBeenCalledTimes(12);
87+
expect(AWS.config.httpOptions).toMatchInlineSnapshot(`
88+
Object {
89+
"timeout": 220000,
90+
}
91+
`);
8092
expect(setFailed).toHaveBeenCalled();
8193
expect(setOutput).not.toHaveBeenCalled();
8294
});
83-
8495
});
85-

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ inputs:
3737
Qualifier:
3838
description: "Specify a version or alias to invoke a published version of the function."
3939
required: false
40+
HTTP_TIMEOUT:
41+
description: Sets the socket to timeout after timeout milliseconds of inactivity on the socket. Defaults to two minutes (120000)
42+
required: false
43+
MAX_RETRIES:
44+
description: Returns the maximum amount of retries to perform for a service request. By default this value is calculated by the specific service object that the request is being made to.
45+
required: false
4046
outputs:
4147
response: # id of output
4248
description: "response from lambda invocation"

dist/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9140,13 +9140,17 @@ var core = __webpack_require__(470);
91409140

91419141

91429142
const apiVersion = '2015-03-31';
9143+
var ExtraOptions;
9144+
(function (ExtraOptions) {
9145+
ExtraOptions["HTTP_TIMEOUT"] = "HTTP_TIMEOUT";
9146+
ExtraOptions["MAX_RETRIES"] = "MAX_RETRIES";
9147+
})(ExtraOptions || (ExtraOptions = {}));
91439148
var Credentials;
91449149
(function (Credentials) {
91459150
Credentials["AWS_ACCESS_KEY_ID"] = "AWS_ACCESS_KEY_ID";
91469151
Credentials["AWS_SECRET_ACCESS_KEY"] = "AWS_SECRET_ACCESS_KEY";
91479152
Credentials["AWS_SESSION_TOKEN"] = "AWS_SESSION_TOKEN";
91489153
})(Credentials || (Credentials = {}));
9149-
;
91509154
var Props;
91519155
(function (Props) {
91529156
Props["FunctionName"] = "FunctionName";
@@ -9156,12 +9160,11 @@ var Props;
91569160
Props["Payload"] = "Payload";
91579161
Props["Qualifier"] = "Qualifier";
91589162
})(Props || (Props = {}));
9159-
;
91609163
const setAWSCredentials = () => {
91619164
global_default.a.config.credentials = {
91629165
accessKeyId: Object(core.getInput)(Credentials.AWS_ACCESS_KEY_ID),
91639166
secretAccessKey: Object(core.getInput)(Credentials.AWS_SECRET_ACCESS_KEY),
9164-
sessionToken: Object(core.getInput)(Credentials.AWS_SESSION_TOKEN)
9167+
sessionToken: Object(core.getInput)(Credentials.AWS_SESSION_TOKEN),
91659168
};
91669169
};
91679170
const getParams = () => {
@@ -9170,9 +9173,20 @@ const getParams = () => {
91709173
return value ? Object.assign(Object.assign({}, memo), { [prop]: value }) : memo;
91719174
}, {});
91729175
};
9176+
const setAWSConfigOptions = () => {
9177+
const httpTimeout = Object(core.getInput)(ExtraOptions.HTTP_TIMEOUT);
9178+
if (httpTimeout) {
9179+
global_default.a.config.httpOptions = { timeout: parseInt(httpTimeout, 10) };
9180+
}
9181+
const maxRetries = Object(core.getInput)(ExtraOptions.MAX_RETRIES);
9182+
if (maxRetries) {
9183+
global_default.a.config.maxRetries = parseInt(maxRetries, 10);
9184+
}
9185+
};
91739186
const main = async () => {
91749187
try {
91759188
setAWSCredentials();
9189+
setAWSConfigOptions();
91769190
const params = getParams();
91779191
const lambda = new lambda_default.a({ apiVersion, region: Object(core.getInput)('REGION') });
91789192
const response = await lambda.invoke(params).promise();

dist/src/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
export declare enum ExtraOptions {
2+
HTTP_TIMEOUT = "HTTP_TIMEOUT",
3+
MAX_RETRIES = "MAX_RETRIES"
4+
}
15
export declare enum Credentials {
26
AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID",
37
AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY",

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "invoke-aws-lambda",
33
"repository": "[email protected]:gagoar/invoke-aws-lambda.git",
44
"license": "MIT",
5-
"version": "3.0.0",
5+
"version": "3.2.0",
66
"description": "Invoke AWS Lambda",
77
"main": "index.ts",
88
"husky": {
@@ -30,10 +30,12 @@
3030
],
3131
"*.ts": [
3232
"eslint --fix",
33-
"bash -c \"npm run build\""
33+
"bash -c \"npm run build\"",
34+
"git add ."
3435
]
3536
},
3637
"eslintConfig": {
38+
"ignorePatterns": "dist/",
3739
"extends": [
3840
"plugin:@typescript-eslint/recommended",
3941
"prettier",

readme.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ This action allows you to synchronously invoke a Lambda function and get the res
1919

2020
## Table of contents
2121

22-
- [Input parameters](#input-parameters)
23-
- [Credentials](#credentials)
24-
- [Invocation](#invocation)
25-
- [Output](#output)
26-
- [Examples](#examples)
27-
- [Basic example](#basic-example)
28-
- [Using output](#using-output)
29-
- [Specifying alias/version](#specifying-aliasversion)
30-
- [Handling logs](#handling-logs)
22+
- [Input parameters](#input-parameters)
23+
- [Credentials](#credentials)
24+
- [Invocation](#invocation)
25+
- [Output](#output)
26+
- [Examples](#examples)
27+
- [Basic example](#basic-example)
28+
- [Using output](#using-output)
29+
- [Specifying alias/version](#specifying-aliasversion)
30+
- [Handling logs](#handling-logs)
3131

3232
<hr>
3333

@@ -47,14 +47,16 @@ This action allows you to synchronously invoke a Lambda function and get the res
4747

4848
### Invocation
4949

50-
| Key | Type | Required | Description |
51-
| ---------------- | :------------------------------------------: | :------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52-
| `FunctionName` | `string` | Yes | Name of the Lambda function to be invoked. |
53-
| `InvocationType` | `RequestResponse\|`<br>`Event\|`<br>`DryRun` | No | Default `RequestResponse`. See the [AWS Javascript SDK docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property) for more info. |
54-
| `LogType` | `Tail\|None` | No | Default `None`. Set to `Tail` to include the execution log in the response. |
55-
| `Payload` | `string` | No | JSON that you want to provide to your Lambda function as input. |
56-
| `Qualifier` | `string` | No | Version or alias of the function to be invoked. |
57-
| `ClientContext` | `string` | No | Base64-encoded data about the invoking client to pass to the function. |
50+
| Key | Type | Required | Description |
51+
| ---------------- | :------------------------------------------: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
52+
| `FunctionName` | `string` | Yes | Name of the Lambda function to be invoked. |
53+
| `InvocationType` | `RequestResponse\|`<br>`Event\|`<br>`DryRun` | No | Default `RequestResponse`. See the [AWS Javascript SDK docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property) for more info. |
54+
| `LogType` | `Tail\|None` | No | Default `None`. Set to `Tail` to include the execution log in the response. |
55+
| `Payload` | `string` | No | JSON that you want to provide to your Lambda function as input. |
56+
| `Qualifier` | `string` | No | Version or alias of the function to be invoked. |
57+
| `ClientContext` | `string` | No | Base64-encoded data about the invoking client to pass to the function. |
58+
| `HTTP_TIMEOUT` | `number` | No | Sets the socket to timeout after timeout milliseconds of inactivity on the socket. Defaults to two minutes (120000). See the [AWS Javascript SDK docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html) |
59+
| `MAX_RETRIES` | `number` | No | Returns the maximum amount of retries to perform for a service request. By default this value is calculated by the specific service object that the request is being made to. [AWS Javascript SDK docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#maxRetries-property) |
5860

5961
For more details on the parameters accepted by `Lambda.invoke()`, see the [AWS Javascript SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property) docs
6062

@@ -153,4 +155,4 @@ These steps process logs returned from the invocation:
153155
Payload: '{ "myParameter": false }'
154156
- name: Store tail logs to file
155157
run: echo "${{ fromJSON(steps.foobar.outputs.response).LogResult }}" > invocation-logs.json
156-
```
158+
```

src/index.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@ import { getInput, setOutput, setFailed } from '@actions/core';
44

55
const apiVersion = '2015-03-31';
66

7+
export enum ExtraOptions {
8+
HTTP_TIMEOUT = 'HTTP_TIMEOUT',
9+
MAX_RETRIES = 'MAX_RETRIES',
10+
}
11+
712
export enum Credentials {
813
AWS_ACCESS_KEY_ID = 'AWS_ACCESS_KEY_ID',
914
AWS_SECRET_ACCESS_KEY = 'AWS_SECRET_ACCESS_KEY',
10-
AWS_SESSION_TOKEN = 'AWS_SESSION_TOKEN'
11-
};
15+
AWS_SESSION_TOKEN = 'AWS_SESSION_TOKEN',
16+
}
1217

1318
export enum Props {
1419
FunctionName = 'FunctionName',
1520
InvocationType = 'InvocationType',
1621
LogType = 'LogType',
1722
ClientContext = 'ClientContext',
1823
Payload = 'Payload',
19-
Qualifier = 'Qualifier'
20-
};
24+
Qualifier = 'Qualifier',
25+
}
2126

2227
const setAWSCredentials = () => {
2328
AWS.config.credentials = {
2429
accessKeyId: getInput(Credentials.AWS_ACCESS_KEY_ID),
2530
secretAccessKey: getInput(Credentials.AWS_SECRET_ACCESS_KEY),
26-
sessionToken: getInput(Credentials.AWS_SESSION_TOKEN)
31+
sessionToken: getInput(Credentials.AWS_SESSION_TOKEN),
2732
};
2833
};
2934

@@ -34,20 +39,33 @@ const getParams = () => {
3439
}, {} as Lambda.InvocationRequest);
3540
};
3641

42+
const setAWSConfigOptions = () => {
43+
const httpTimeout = getInput(ExtraOptions.HTTP_TIMEOUT);
44+
45+
if (httpTimeout) {
46+
AWS.config.httpOptions = { timeout: parseInt(httpTimeout, 10) };
47+
}
48+
49+
const maxRetries = getInput(ExtraOptions.MAX_RETRIES);
50+
51+
if (maxRetries) {
52+
AWS.config.maxRetries = parseInt(maxRetries, 10);
53+
}
54+
};
3755
export const main = async () => {
3856
try {
39-
4057
setAWSCredentials();
4158

59+
setAWSConfigOptions();
60+
4261
const params = getParams();
4362

4463
const lambda = new Lambda({ apiVersion, region: getInput('REGION') });
4564

4665
const response = await lambda.invoke(params).promise();
4766

4867
setOutput('response', response);
49-
5068
} catch (error) {
5169
setFailed(error.message);
5270
}
53-
};
71+
};

tsconfig.eslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"index.ts",
66
"__mocks__/**/*.ts",
77
"__tests__/**/*.ts",
8-
"jest.config.js"
8+
"jest.config.js",
9+
"!dist/"
910
]
1011
}

0 commit comments

Comments
 (0)