Skip to content

Commit e5169b2

Browse files
author
Chris Wiechmann
authored
Merge pull request #8 from Axway-API-Builder-Ext/aws-lambda
Add AWS Lambda flow node
2 parents 0215caf + 963dcee commit e5169b2

23 files changed

+1674
-6
lines changed

.github/workflows/plugin-fn-aws-athena-publish.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jobs:
2525
- name: Run npm tests
2626
working-directory: ${{env.workingDirectory}}
2727
env:
28-
AWS_ATHENA_SECRET: ${{ secrets.AWS_ATHENA_SECRET }}
28+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
29+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
2930
run: |
3031
npm ci
3132
npm test
@@ -48,7 +49,8 @@ jobs:
4849
working-directory: ${{env.workingDirectory}}
4950
env:
5051
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
51-
AWS_ATHENA_SECRET: ${{ secrets.AWS_ATHENA_SECRET }}
52+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
53+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
5254
run: |
5355
npm ci
5456
npm publish
@@ -70,7 +72,8 @@ jobs:
7072
working-directory: ${{env.workingDirectory}}
7173
env:
7274
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
73-
AWS_ATHENA_SECRET: ${{ secrets.AWS_ATHENA_SECRET }}
75+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
7477
run: |
7578
npm ci
7679
echo "//registry.npmjs.org/:_authToken=${{ secrets.npm_token }}" > ~/.npmrc

.github/workflows/plugin-fn-aws-athena-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ jobs:
3434
working-directory: ${{env.workingDirectory}}
3535
env:
3636
CI: true
37-
AWS_ATHENA_SECRET: ${{ secrets.AWS_ATHENA_SECRET }}
37+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
38+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
3839
run: |
3940
npm ci
4041
npm run build --if-present
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# The name of the plugin to appear in the actions and badge!
2+
name: AWS Lambda Release
3+
4+
on:
5+
release:
6+
types:
7+
- published
8+
tags:
9+
# If this tag is pushed, a release is created
10+
- '*plugin-fn-aws-lambda*'
11+
12+
jobs:
13+
build:
14+
# This is a required check, as the on:release can't be filtered on given tags
15+
if: contains(github.ref, 'plugin-fn-aws-lambda')
16+
env:
17+
# This must be aligned with the folder-name of you plugin
18+
workingDirectory: 'api-builder-plugin-fn-aws-lambda'
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v1
22+
- uses: actions/setup-node@v1
23+
with:
24+
node-version: 12
25+
- name: Run npm tests
26+
working-directory: ${{env.workingDirectory}}
27+
env:
28+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
29+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
30+
run: |
31+
npm ci
32+
npm test
33+
34+
publish-gpr:
35+
env:
36+
# This must be aligned with the folder-name of you plugin
37+
workingDirectory: 'api-builder-plugin-fn-aws-athena'
38+
CI: true
39+
needs: build
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v1
43+
- uses: actions/setup-node@v1
44+
with:
45+
node-version: 12
46+
registry-url: https://npm.pkg.github.com/
47+
scope: '@Axway-API-Builder-Ext'
48+
- name: Publish to GitHub package repo
49+
working-directory: ${{env.workingDirectory}}
50+
env:
51+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
52+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
53+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
54+
run: |
55+
npm ci
56+
npm publish
57+
58+
publish-npm:
59+
env:
60+
# This must be aligned with the folder-name of you plugin
61+
workingDirectory: 'api-builder-plugin-fn-aws-athena'
62+
CI: true
63+
needs: [build, publish-gpr]
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v1
67+
- uses: actions/setup-node@v1
68+
with:
69+
node-version: 12
70+
registry-url: https://registry.npmjs.org/
71+
- name: Publish to NPM package repo
72+
working-directory: ${{env.workingDirectory}}
73+
env:
74+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
75+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
77+
run: |
78+
npm ci
79+
echo "//registry.npmjs.org/:_authToken=${{ secrets.npm_token }}" > ~/.npmrc
80+
npm publish --access public
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# The name of the workflow node to appear in the actions and badge!
2+
name: AWS Lambda Tests
3+
4+
on:
5+
push:
6+
paths:
7+
# This must be aligned with the folder-name of you plugin
8+
- 'api-builder-plugin-fn-aws-lambda/**'
9+
- '.github/workflows/**'
10+
pull_request:
11+
paths:
12+
# This must be aligned with the folder-name of you plugin
13+
- 'api-builder-plugin-fn-aws-lambda/**'
14+
- '.github/workflows/**'
15+
16+
jobs:
17+
build:
18+
env:
19+
# This must be aligned with the folder-name of you plugin
20+
workingDirectory: 'api-builder-plugin-fn-aws-lambda'
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
node-version: [8.x, 10.x, 12.x]
25+
steps:
26+
# - name: Debug
27+
# uses: hmarr/debug-action@v1.0.0
28+
- uses: actions/checkout@v1
29+
- name: default deploy
30+
uses: appleboy/lambda-action@master
31+
with:
32+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
33+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
34+
aws_region: us-east-1
35+
function_name: greeting
36+
source: api-builder-plugin-fn-aws-lambda/test/lambdaFunction/index.js
37+
- name: Use Node.js ${{ matrix.node-version }}
38+
uses: actions/setup-node@v1
39+
with:
40+
node-version: ${{ matrix.node-version }}
41+
- name: npm install, build, and test
42+
working-directory: ${{env.workingDirectory}}
43+
env:
44+
CI: true
45+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
47+
run: |
48+
npm ci
49+
npm run build --if-present
50+
npm test

api-builder-plugin-fn-aws-athena/test/config/aws-athena.testconfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module.exports = {
55
'aws': {
66
credentials: {
77
region: "us-east-1",
8-
accessKeyId: "AKIAT5BVQVJFLVYIWNOP",
9-
secretAccessKey: process.env.AWS_ATHENA_SECRET
8+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
9+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
1010
}
1111
}
1212
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# next.js build output
61+
.next
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
![AWS Lambda Tests](https://github.com/Axway-API-Builder-Ext/api-builder-extras/workflows/AWS%20Lambda%20Tests/badge.svg)
2+
3+
# API-Builder AWS-Lambda Flow-Node
4+
5+
If you would like to integrate AWS Lambda functions into your [API-Builder flow][1] use this flow node.
6+
It allows you to easily call your Lambda-Functions and merge, transform or use the returned data in any way you want.
7+
8+
## Configuration
9+
10+
After installation and restarting your API-Builder project you get the following new flow-node:
11+
![Node][img1]
12+
Before you can make use it in your flow you have to configure your AWS-Credentials allowed to invoke Lambda functions.
13+
14+
During installation a new config file has been automatically created which must be completed with your AWS Credentials. You can do that directly from within the API-Builder UI:
15+
![Config][img3]
16+
We recommend to setup your configuration in a [environmentalized][4] way keeping [sensitive information][5] away from the source-code repository.
17+
18+
## Invoke Lambda functions
19+
To invoke a Lambda function, just drag & drop the Flow-Node into your flow and set it up as described here.
20+
![Node][img2]
21+
22+
### Input parameters
23+
24+
| Param | Type | Required | Description |
25+
| --- | --- | --- | --- |
26+
| func | string | y | The name of the AWS-Lambda-Function to call. |
27+
| payload | JSON or Object | n | Input information required by the Lambda-Function. Example: `{"key1":"value1"}` |
28+
| asynchronous | boolean | n | If enabled the Lambda function is invoked asyncronously and no data is returned. Read more here: https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html. |
29+
| logResult | boolean | n | If enabled, the Tail option is used when invoking the Lambda function and logged in the API Builder Console. |
30+
31+
### Output
32+
If the function wasn't invoked asynchronously you get back the `data.Payload` into attribute configured with next. By default: `$.result`. For example, having the following AWS-Lambda function:
33+
```js
34+
exports.handler = async (event) => {
35+
const response = {
36+
statusCode: 200,
37+
body: "Hello from " + event.key1 + " from AWS-Lambda!"
38+
};
39+
return response;
40+
};
41+
```
42+
Using the payload: `{"key1":"Chris"}` the attribute `$.result` will contain the following: `Howdy Hello from Chris from AWS-Lambda!`.
43+
In case of an error the attribute: `$.error` contains the error returned by AWS or by the Lambda-Fow-Node.
44+
45+
If the function is invoked asynchronously no data is returned. The attribute: `$.result` just contains the value: `Accepted`.
46+
47+
## Compatibility
48+
Tested with AWS Lambda Q1/2020
49+
Requires API-Builder Independence or higher
50+
51+
## Changelog
52+
- 1.0.0 - 18.02.2020
53+
- Initial version
54+
55+
## Limitations/Caveats
56+
Noting known
57+
58+
## Contributing
59+
60+
Please read [Contributing.md](https://github.com/Axway-API-Management-Plus/Common/blob/master/Contributing.md) for details on our code of conduct, and the process for submitting pull requests to us.
61+
62+
## Team
63+
64+
![alt text][Axwaylogo] Axway Team
65+
66+
[Axwaylogo]: https://github.com/Axway-API-Management/Common/blob/master/img/AxwayLogoSmall.png "Axway logo"
67+
68+
[1]: https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/api_builder_flows.html
69+
[2]: https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/api_builder_getting_started_guide.html
70+
[3]: https://github.com/Axway-API-Builder-Ext/api-builder-extras/issues
71+
[4]: https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/environmentalization.html
72+
[5]: https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/project_configuration.html#ProjectConfiguration-Configurationfiles
73+
74+
[img1]: imgs/lambda-flownode.png
75+
[img2]: imgs/lambda-invoke.png
76+
[img3]: imgs/Lambda-Connector-Config.png
77+
[img4]: imgs/Lambda-Connector-Config-File.png
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
pluginConfig: {
3+
'@axway-api-builder-ext/api-builder-plugin-fn-aws-lambda': {
4+
'aws': {
5+
credentials: {
6+
region: process.env.AWS_ACCESS_REGION,
7+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
8+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
9+
}
10+
}
11+
}
12+
}
13+
};
13.3 KB
Loading
11.4 KB
Loading

0 commit comments

Comments
 (0)