Skip to content

Commit

Permalink
Increase test coverage of instrumentation-aws-lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
jbfenton committed Aug 4, 2024
1 parent ca0dd50 commit e39d67b
Show file tree
Hide file tree
Showing 7 changed files with 448 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
MOCK_LAMBDA_ALB_EVENT = {
"requestContext": {
"elb": {
"targetGroupArn": "arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-target-group/6d0ecf831eec9f09"
}
},
"httpMethod": "GET",
"path": "/",
"queryStringParameters": {"foo": "bar"},
"headers": {
"accept": "text/html,application/xhtml+xml",
"accept-language": "en-US,en;q=0.8",
"content-type": "text/plain",
"cookie": "cookies",
"host": "lambda-846800462-us-east-2.elb.amazonaws.com",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)",
"x-amzn-trace-id": "Root=1-5bdb40ca-556d8b0c50dc66f0511bf520",
"x-forwarded-for": "72.21.198.66",
"x-forwarded-port": "443",
"x-forwarded-proto": "https",
},
"isBase64Encoded": False,
"body": "request_body",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers
When an ALB is configured to send multi-value headers, the headers are sent as a list of values under the key in the multiValueHeaders object.
"""

MOCK_LAMBDA_ALB_MULTI_VALUE_HEADER_EVENT = {
"requestContext": {
"elb": {
"targetGroupArn": "arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-target-group/6d0ecf831eec9f09"
}
},
"httpMethod": "GET",
"path": "/",
"queryStringParameters": {"foo": "bar"},
"multiValueHeaders": {
"accept": ["text/html,application/xhtml+xml"],
"accept-language": ["en-US,en;q=0.8"],
"content-type": ["text/plain"],
"cookie": ["cookies"],
"host": ["lambda-846800462-us-east-2.elb.amazonaws.com"],
"user-agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)"],
"x-amzn-trace-id": ["Root=1-5bdb40ca-556d8b0c50dc66f0511bf520"],
"x-forwarded-for": ["72.21.198.66"],
"x-forwarded-port": ["443"],
"x-forwarded-proto": ["https"],
},
"isBase64Encoded": False,
"body": "request_body",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
"""

MOCK_LAMBDA_DYNAMO_DB_EVENT = {
"Records": [
{
"eventID": "1",
"eventVersion": "1.0",
"dynamodb": {
"Keys": {"Id": {"N": "101"}},
"NewImage": {
"Message": {"S": "New item!"},
"Id": {"N": "101"},
},
"StreamViewType": "NEW_AND_OLD_IMAGES",
"SequenceNumber": "111",
"SizeBytes": 26,
},
"awsRegion": "us-west-2",
"eventName": "INSERT",
"eventSourceARN": "arn:aws:dynamodb:us-east-2:123456789012:table/my-table/stream/2023-06-10T19:26:16.525",
"eventSource": "aws:dynamodb",
},
{
"eventID": "2",
"eventVersion": "1.0",
"dynamodb": {
"OldImage": {
"Message": {"S": "New item!"},
"Id": {"N": "101"},
},
"SequenceNumber": "222",
"Keys": {"Id": {"N": "101"}},
"SizeBytes": 59,
"NewImage": {
"Message": {"S": "This item has changed"},
"Id": {"N": "101"},
},
"StreamViewType": "NEW_AND_OLD_IMAGES",
},
"awsRegion": "us-west-2",
"eventName": "MODIFY",
"eventSourceARN": "arn:aws:dynamodb:us-east-2:123456789012:table/my-table/stream/2023-06-10T19:26:16.525",
"eventSource": "aws:dynamodb",
},
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
"""

MOCK_LAMBDA_S3_EVENT = {
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "us-east-2",
"eventTime": "2019-09-03T19:37:27.192Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {"principalId": "AWS:AIDAINPONIXQXHT3IKHL2"},
"requestParameters": {"sourceIPAddress": "205.255.255.255"},
"responseElements": {
"x-amz-request-id": "D82B88E5F771F645",
"x-amz-id-2": "vlR7PnpV2Ce81l0PRw6jlUpck7Jo5ZsQjryTjKlc5aLWGVHPZLj5NeC6qMa0emYBDXOo6QBU0Wo=",
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "828aa6fc-f7b5-4305-8584-487c791949c1",
"bucket": {
"name": "DOC-EXAMPLE-BUCKET",
"ownerIdentity": {"principalId": "A3I5XTEXAMAI3E"},
"arn": "arn:aws:s3:::lambda-artifacts-deafc19498e3f2df",
},
"object": {
"key": "b21b84d653bb07b05b1e6b33684dc11b",
"size": 1305107,
"eTag": "b21b84d653bb07b05b1e6b33684dc11b",
"sequencer": "0C0F6F405D6ED209E1",
},
},
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html
"""

MOCK_LAMBDA_SNS_EVENT = {
"Records": [
{
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:us-east-1:123456789012:sns-lambda:21be56ed-a058-49f5-8c98-aedd2564c486",
"EventSource": "aws:sns",
"Sns": {
"SignatureVersion": "1",
"Timestamp": "2019-01-02T12:45:07.000Z",
"Signature": "mock-signature",
"SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-ac565b8b1a6c5d002d285f9598aa1d9b.pem",
"MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
"Message": "Hello from SNS!",
"MessageAttributes": {
"Test": {"Type": "String", "Value": "TestString"},
"TestBinary": {"Type": "Binary", "Value": "TestBinary"},
},
"Type": "Notification",
"UnsubscribeURL": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:123456789012:test-lambda:21be56ed-a058-49f5-8c98-aedd2564c486",
"TopicArn": "arn:aws:sns:us-east-1:123456789012:sns-lambda",
"Subject": "TestInvoke",
},
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
"""

MOCK_LAMBDA_SQS_EVENT = {
"Records": [
{
"messageId": "059f36b4-87a3-44ab-83d2-661975830a7d",
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...",
"body": "Test message.",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1545082649183",
"SenderId": "AIDAIENQZJOLO23YVJ4VO",
"ApproximateFirstReceiveTimestamp": "1545082649185",
},
"messageAttributes": {},
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
"eventSource": "aws:sqs",
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue",
"awsRegion": "us-east-2",
}
]
}
Loading

0 comments on commit e39d67b

Please sign in to comment.