Skip to content

fix(lambda-function): parse LastModified as a timestamp - #1062

Open
lbarrosby wants to merge 1 commit into
ekristen:mainfrom
lbarrosby:fix/lambda-function-last-modified-time
Open

lbarrosby wants to merge 1 commit into
ekristen:mainfrom
lbarrosby:fix/lambda-function-last-modified-time

Conversation

@lbarrosby

Copy link
Copy Markdown

Fixes #858

LambdaFunction.LastModified was stored as the raw string from ListFunctions, which Lambda returns as 2019-08-14T22:32:35.183+0000. That is not RFC 3339 (no colon in the offset) and is none of the layouts libnuke's parseDate accepts, so any dateOlderThan / dateOlderThanNow filter on LastModified (the use case from #818) fails with unable to parse time ....

The lister now parses the value with Lambda's layout into a *time.Time (UTC). NewPropertiesFromStruct already renders time.Time as RFC 3339, so the property becomes 2019-08-14T22:32:35Z and the date filters work. If the value cannot be parsed, the property is left empty instead of carrying an unusable string.

Testing

New resources/lambda-function_mock_test.go runs the real LambdaFunctionLister against an httptest server that returns a ListFunctions / ListTags response with the exact Lambda timestamp format, then checks the property value and runs a dateOlderThanNow filter on it.

$ go test ./resources/ -run TestLambdaFunction_ -count=1
# before
--- FAIL: TestLambdaFunction_LastModifiedIsTimestamp
        expected: "2019-08-14T22:32:35Z"
        actual  : "2019-08-14T22:32:35.183+0000"
--- FAIL: TestLambdaFunction_LastModifiedDateOlderThanNowFilter
        Received unexpected error: unable to parse time 2019-08-14T22:32:35.183+0000
# after
ok  	github.com/ekristen/aws-nuke/v3/resources	0.839s

go test ./resources/ and golangci-lint run ./resources/ report nothing new for the changed files.

This change was prepared with help from an AI coding assistant; I reviewed and tested it.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lambda LastModified string breaks timestamp filtering

1 participant