-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add support for Lambda #76
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AWSConfig, LambdaClient } from '../build/lambda.js' | ||
import { check } from 'k6'; | ||
|
||
const awsConfig = new AWSConfig({ | ||
region: __ENV.AWS_REGION, | ||
accessKeyId: __ENV.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY, | ||
sessionToken: __ENV.AWS_SESSION_TOKEN, | ||
}) | ||
|
||
const lambdaClient = new LambdaClient(awsConfig) | ||
|
||
export default async function () { | ||
const response = await lambdaClient.invoke('add-numbers', JSON.stringify({x: 1, y: 2})) | ||
|
||
check(response, { | ||
'status is 200': (r) => r.statusCode === 200, | ||
'payload is 3': (r) => r.payload === 3, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
#!/bin/bash | ||
|
||
FUNCTION_NAME="test-jslib-aws-lambda" | ||
testdata_folder="/etc/localstack/init/testdata/lambda" | ||
zip_dir=/tmp/lambda | ||
mkdir -p "$zip_dir" | ||
|
||
# Create a dummy lambda function responding with a static string "Hello World!" | ||
cat >index.js <<EOF | ||
exports.handler = async function(event, context) { | ||
return "Hello World!"; | ||
} | ||
EOF | ||
for file in "$testdata_folder"/*; do | ||
function_name=$(basename "$file") | ||
function_zip="$zip_dir/$function_name.zip" | ||
(cd "$file" || exit; zip "$function_zip" ./*) | ||
Comment on lines
+3
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nickcaballero do we need to have them nested in folders? Could we have direct a list of files? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file structure matches how the zips are created. We can flatten the folders, but it'll make the script a bit more complicated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to have a simpler script, rather than a simpler folder structure 👍🏻 |
||
|
||
# Create a zip file containing the lambda function | ||
zip lambda.zip index.js | ||
|
||
# Create a dummy lambda function responding with a static string "Hello World!" | ||
awslocal lambda create-function \ | ||
--function-name "$FUNCTION_NAME" \ | ||
--runtime nodejs18.x \ | ||
--handler index.handler \ | ||
--zip-file fileb://lambda.zip \ | ||
--role arn:aws:iam::123456789012:role/irrelevant | ||
awslocal lambda create-function \ | ||
--function-name "$function_name" \ | ||
--runtime nodejs18.x \ | ||
--zip-file "fileb://$function_zip" \ | ||
--handler index.handler \ | ||
--role arn:aws:iam::000000000000:role/lambda-role | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.handler = async (event) => { | ||
throw new Error(event) | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exports.handler = async (event) => { | ||
console.log('received event:', JSON.stringify(event)); | ||
return event.a * event.b | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { parseHTML } from 'k6/html' | ||
import { Response } from 'k6/http' | ||
|
||
/** | ||
* Base class to derive errors from | ||
|
@@ -35,4 +36,15 @@ export class AWSError extends Error { | |
const doc = parseHTML(xmlDocument) | ||
return new AWSError(doc.find('Message').text(), doc.find('Code').text()) | ||
} | ||
|
||
static parse(response: Response): AWSError { | ||
if (response.headers['Content-Type'] === 'application/json') { | ||
const error = response.json() as any; | ||
const message = error.Message || error.message || error.__type || 'An error occurred on the server side'; | ||
const code = response.headers['X-Amzn-Errortype'] || error.__type | ||
return new AWSError(message, code) | ||
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pulled some of the error handling logic that @jakub-qg added into here to make it more reusable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really neat 🙇🏻 |
||
} else { | ||
return AWSError.parseXML(response.body as string); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect we need to bump, right @oleiade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codebien So far bumping version numbering has been part of our release process, and we haven't done it in feature PRs.
Although I realize we haven't added it to our CONTRIBUTING guidelines yet, will do so 👍🏻