Skip to content

Commit 732dcfd

Browse files
removed delete validation
1 parent fb5a5fa commit 732dcfd

2 files changed

Lines changed: 8 additions & 36 deletions

File tree

cfn/wrap.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77
"encoding/json"
88
"errors"
9-
"fmt"
109
"log"
1110
"net/http"
1211

@@ -58,11 +57,7 @@ func lambdaWrapWithClient(lambdaFunction CustomResourceFunction, client httpClie
5857
if err != nil {
5958
r.Status = StatusFailed
6059
r.Reason = err.Error()
61-
log.Printf("sending status failed: %s", r.Reason)
62-
} else if event.RequestType == RequestDelete && event.PhysicalResourceID != r.PhysicalResourceID {
63-
r.Status = StatusFailed
64-
r.Reason = fmt.Sprintf("DELETE: cannot change the physical resource ID from %s to %s during deletion", event.PhysicalResourceID, r.PhysicalResourceID)
65-
log.Printf("sending status failed: %s", r.Reason)
60+
log.Printf("sending status failed: %s\n", r.Reason)
6661
} else {
6762
r.Status = StatusSuccess
6863
}

cfn/wrap_test.go

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func TestLambdaPhysicalResourceId(t *testing.T) {
6060
// For Delete with returned PhysicalResourceID = old PhysicalResourceID
6161
{RequestDelete, nil, "prevPhysicalResourceID", "prevPhysicalResourceID"},
6262
{RequestDelete, fmt.Errorf("dummy error"), "prevPhysicalResourceID", "prevPhysicalResourceID"},
63+
64+
// For Delete with returned PhysicalResourceID != old PhysicalResourceID
65+
// Technically, lambda handlers shouldn't return a different physical resource id upon deletion.
66+
// Typescript CDK implementation for handlers would return an error here.
67+
// But CFn ignores the returned PhysicalResourceID for deletion (if deletion succeeds) so it doesn't matter.
68+
{RequestDelete, nil, "newPhysicalResourceID", "newPhysicalResourceID"},
69+
{RequestDelete, fmt.Errorf("dummy error"), "newPhysicalResourceID", "newPhysicalResourceID"},
6370
}
6471
for _, test := range tests {
6572

@@ -99,36 +106,6 @@ func TestLambdaPhysicalResourceId(t *testing.T) {
99106
}
100107
}
101108

102-
func TestDeleteFailsWhenPhysicalResourceIDChanges(t *testing.T) {
103-
104-
curTestEvent := *testEvent
105-
curTestEvent.RequestType = RequestDelete
106-
107-
client := &mockClient{
108-
DoFunc: func(req *http.Request) (*http.Response, error) {
109-
response := extractResponseBody(t, req)
110-
111-
// Status should be Failed because the PhysicalResourceID changed
112-
assert.Equal(t, StatusFailed, response.Status)
113-
assert.Equal(t, curTestEvent.LogicalResourceID, response.LogicalResourceID)
114-
assert.Equal(t, "newPhysicalResourceID", response.PhysicalResourceID)
115-
116-
return &http.Response{
117-
StatusCode: http.StatusOK,
118-
Body: nopCloser{bytes.NewBufferString("")},
119-
}, nil
120-
},
121-
}
122-
123-
fn := func(ctx context.Context, event Event) (physicalResourceID string, data map[string]interface{}, err error) {
124-
return "newPhysicalResourceID", nil, nil // No error but a "newPhysicalResourceID" is returned
125-
}
126-
127-
_, err := lambdaWrapWithClient(fn, client)(context.TODO(), curTestEvent)
128-
assert.NoError(t, err)
129-
130-
}
131-
132109
func TestPanicSendsFailure(t *testing.T) {
133110
didSendStatus := false
134111

0 commit comments

Comments
 (0)