-
Notifications
You must be signed in to change notification settings - Fork 564
feat(events): add VPC Lattice request/response types #521
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
Open
nmoutschen
wants to merge
6
commits into
aws:main
Choose a base branch
from
nmoutschen:vpc-lattice-events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
de2a65f
feat(events): add VPC Lattice request/response types
nmoutschen 055323f
fix: add isBase64Encoded for VPCLatticeRequestV2
nmoutschen 9465179
fix: fix lints
nmoutschen 85a847f
Merge branch 'main' into vpc-lattice-events
bmoffatt f3eddf5
Update vpclattice.go per linter
bmoffatt 1848e40
Merge branch 'main' into vpc-lattice-events
bmoffatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"isBase64Encoded": true, | ||
"statusCode": 200, | ||
"statusDescription": "200 OK", | ||
"headers": { | ||
"set-cookie": "cookies", | ||
"content-type": "application/json" | ||
}, | ||
"body": "BODY" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"raw_path": "/", | ||
"method": "POST", | ||
"headers": { | ||
"accept-encoding": "gzip, br, deflate", | ||
"accept": "application/json", | ||
"content-length": "4", | ||
"content-type": "application/json", | ||
"host": "some-host.vpc-lattice-svcs.us-east-1.on.aws", | ||
"x-forwarded-for": "1.2.3.4,2.3.4.5", | ||
"x-forwarded-port": "443" | ||
}, | ||
"query_string_parameters": {}, | ||
"body": "BODY", | ||
"is_base64_encoded": true | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "2.0", | ||
"path": "/", | ||
"method": "POST", | ||
"headers": { | ||
"accept": [ | ||
"application/json" | ||
], | ||
"x-forwarded-port": [ | ||
"443" | ||
], | ||
"x-forwarded-for": [ | ||
"1.2.3.4,2.3.4.5" | ||
], | ||
"host": [ | ||
"some-host.vpc-lattice-svcs.us-east-1.on.aws" | ||
], | ||
"content-type": [ | ||
"application/json" | ||
], | ||
"content-length": [ | ||
"4" | ||
], | ||
"accept-encoding": [ | ||
"gzip, br, deflate" | ||
] | ||
}, | ||
"body": "BODY", | ||
"requestContext": { | ||
"serviceNetworkArn": "arn:aws:vpc-lattice:us-east-1:12346789012:servicenetwork/sn-0db8ae434454b4422", | ||
"serviceArn": "arn:aws:vpc-lattice:us-east-1:12346789012:service/svc-0db8ae434454b4422", | ||
"targetGroupArn": "arn:aws:vpc-lattice:us-east-1:12346789012:targetgroup/tg-0db8ae434454b4422", | ||
"identity": { | ||
"sourceVpcArn": "arn:aws:ec2:us-east-1:12346789012:vpc/vpc-0db8ae434454b4422", | ||
"type": "AWS_IAM", | ||
"principal": "arn:aws:sts::12346789012:assumed-role/IAM_ROLE/SESSION_NAME", | ||
"sessionName": "SESSION_NAME" | ||
}, | ||
"region": "us-east-1", | ||
"timeEpoch": "1695799509392227" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package events | ||
|
||
// VPCLatticeRequestV1 contains data coming from AWS VPC Lattice | ||
type VPCLatticeRequestV1 struct { | ||
RawPath string `json:"raw_path"` | ||
Method string `json:"method"` | ||
Headers map[string]string `json:"headers"` | ||
QueryStringParameters map[string]string `json:"query_string_parameters"` | ||
Body string `json:"body"` | ||
IsBase64Encoded bool `json:"is_base64_encoded,omitempty"` | ||
} | ||
|
||
// VPCLatticeRequestV2 contains data coming from AWS VPC Lattice | ||
type VPCLatticeRequestV2 struct { | ||
Version string `json:"version"` | ||
Path string `json:"path"` | ||
Method string `json:"method"` | ||
Headers map[string][]string `json:"headers"` | ||
Body string `json:"body"` | ||
RequestContext VPCLatticeRequestContext `json:"requestContext"` | ||
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` | ||
} | ||
|
||
// VPCLatticeRequestContext contains metadata about the incoming request | ||
type VPCLatticeRequestContext struct { | ||
ServiceNetworkARN string `json:"serviceNetworkArn"` | ||
ServiceARN string `json:"serviceArn"` | ||
TargetGroupARN string `json:"targetGroupArn"` | ||
Identity *VPCLatticeRequestIdentity `json:"identity,omitempty"` | ||
Region string `json:"region"` | ||
TimeEpoch string `json:"timeEpoch"` | ||
} | ||
|
||
// VpcLatticeRequestIdentity contains information about the caller | ||
type VPCLatticeRequestIdentity struct { | ||
SourceVPCARN string `json:"sourceVpcArn"` | ||
Type string `json:"type"` | ||
Principal string `json:"principal"` | ||
SessionName string `json:"sessionName"` | ||
} | ||
|
||
Comment on lines
+34
to
+41
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. reviewing - https://docs.aws.amazon.com/vpc-lattice/latest/ug/lambda-functions.html#receive-event-from-service missing identity fields
|
||
// VPCLatticeResponse contains the response to be returned to VPC Lattice | ||
type VPCLatticeResponse struct { | ||
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"` | ||
StatusCode int `json:"statusCode"` | ||
StatusDescription string `json:"statusDescription,omitempty"` | ||
Headers map[string]string `json:"headers"` | ||
Body string `json:"body"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package events | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVPCLatticeRequestV1Marshalling(t *testing.T) { | ||
|
||
// read json from file | ||
inputJSON, err := ioutil.ReadFile("./testdata/vpclattice-v1-request.json") | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
// de-serialize into Go object | ||
var inputEvent VPCLatticeRequestV1 | ||
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
|
||
// serialize to json | ||
outputJSON, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
assert.JSONEq(t, string(inputJSON), string(outputJSON)) | ||
} | ||
|
||
func TestVPCLatticeRequestV1MalformedJson(t *testing.T) { | ||
test.TestMalformedJson(t, VPCLatticeRequestV1{}) | ||
} | ||
|
||
func TestVPCLatticeRequestV2Marshalling(t *testing.T) { | ||
|
||
// read json from file | ||
inputJSON, err := ioutil.ReadFile("./testdata/vpclattice-v2-request.json") | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
// de-serialize into Go object | ||
var inputEvent VPCLatticeRequestV2 | ||
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
|
||
// serialize to json | ||
outputJSON, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
assert.JSONEq(t, string(inputJSON), string(outputJSON)) | ||
} | ||
|
||
func TestVPCLatticeRequestV2MalformedJson(t *testing.T) { | ||
test.TestMalformedJson(t, VPCLatticeRequestV2{}) | ||
} | ||
|
||
func TestVPCLatticeResponse(t *testing.T) { | ||
// read json from file | ||
inputJSON, err := ioutil.ReadFile("./testdata/vpclattice-response.json") | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
// de-serialize into Go object | ||
var inputEvent VPCLatticeResponse | ||
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
|
||
// serialize to json | ||
outputJSON, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
assert.JSONEq(t, string(inputJSON), string(outputJSON)) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.