@@ -51,7 +51,8 @@ export async function addSamDebugConfiguration(
51
51
let runtimeName = runtimeFamily ? getDefaultRuntime ( runtimeFamily ) : undefined
52
52
let addRuntimeNameToConfig = false
53
53
54
- if ( type === TEMPLATE_TARGET_TYPE ) {
54
+ // both of these config types use templates
55
+ if ( type === TEMPLATE_TARGET_TYPE || type === API_TARGET_TYPE ) {
55
56
let preloadedConfig = undefined
56
57
57
58
if ( workspaceFolder ) {
@@ -63,36 +64,42 @@ export async function addSamDebugConfiguration(
63
64
}
64
65
65
66
if ( CloudFormation . isZipLambdaResource ( resource . Properties ) ) {
66
- const handler = CloudFormation . getStringForProperty ( resource . Properties . Handler , templateDatum . item )
67
- const existingConfig = await getExistingConfiguration ( workspaceFolder , handler ?? '' , rootUri )
68
- if ( existingConfig ) {
69
- const responseMigrate : string = localize (
70
- 'AWS.sam.debugger.useExistingConfig.migrate' ,
71
- 'Create based on the legacy config'
67
+ if ( type === TEMPLATE_TARGET_TYPE ) {
68
+ const handler = CloudFormation . getStringForProperty (
69
+ resource . Properties . Handler ,
70
+ templateDatum . item
72
71
)
73
- const responseNew : string = localize (
74
- 'AWS.sam.debugger.useExistingConfig.doNotMigrate' ,
75
- 'Create new config only'
76
- )
77
- const prompt = await vscode . window . showInformationMessage (
78
- localize (
79
- 'AWS.sam.debugger.useExistingConfig' ,
80
- 'AWS Toolkit detected an existing legacy configuration for this function. Create the debug config based on the legacy config?'
81
- ) ,
82
- { modal : true } ,
83
- responseMigrate ,
84
- responseNew
85
- )
86
- if ( ! prompt ) {
87
- // User selected "Cancel". Abandon config creation
88
- return
89
- } else if ( prompt === responseMigrate ) {
90
- preloadedConfig = existingConfig
72
+ const existingConfig = await getExistingConfiguration ( workspaceFolder , handler ?? '' , rootUri )
73
+ if ( existingConfig ) {
74
+ const responseMigrate : string = localize (
75
+ 'AWS.sam.debugger.useExistingConfig.migrate' ,
76
+ 'Create based on the legacy config'
77
+ )
78
+ const responseNew : string = localize (
79
+ 'AWS.sam.debugger.useExistingConfig.doNotMigrate' ,
80
+ 'Create new config only'
81
+ )
82
+ const prompt = await vscode . window . showInformationMessage (
83
+ localize (
84
+ 'AWS.sam.debugger.useExistingConfig' ,
85
+ 'AWS Toolkit detected an existing legacy configuration for this function. Create the debug config based on the legacy config?'
86
+ ) ,
87
+ { modal : true } ,
88
+ responseMigrate ,
89
+ responseNew
90
+ )
91
+ if ( ! prompt ) {
92
+ // User selected "Cancel". Abandon config creation
93
+ return
94
+ } else if ( prompt === responseMigrate ) {
95
+ preloadedConfig = existingConfig
96
+ }
91
97
}
92
98
}
93
- } else if ( CloudFormation . isImageLambdaResource ( resource . Properties ) && runtimeFamily === undefined ) {
99
+ } else if ( CloudFormation . isImageLambdaResource ( resource . Properties ) ) {
94
100
const quickPick = createRuntimeQuickPick ( {
95
101
showImageRuntimes : false ,
102
+ runtimeFamily,
96
103
} )
97
104
98
105
const choices = await picker . promptUser ( {
@@ -113,14 +120,32 @@ export async function addSamDebugConfiguration(
113
120
}
114
121
}
115
122
}
116
- samDebugConfig = createTemplateAwsSamDebugConfig (
117
- workspaceFolder ,
118
- runtimeName ,
119
- addRuntimeNameToConfig ,
120
- resourceName ,
121
- rootUri . fsPath ,
122
- preloadedConfig
123
- )
123
+
124
+ if ( type === TEMPLATE_TARGET_TYPE ) {
125
+ samDebugConfig = createTemplateAwsSamDebugConfig (
126
+ workspaceFolder ,
127
+ runtimeName ,
128
+ addRuntimeNameToConfig ,
129
+ resourceName ,
130
+ rootUri . fsPath ,
131
+ preloadedConfig
132
+ )
133
+ } else {
134
+ // If the event has no properties, the default will be used
135
+ const apiConfig = {
136
+ path : apiEvent ?. event . Properties ?. Path ,
137
+ httpMethod : apiEvent ?. event . Properties ?. Method ,
138
+ payload : apiEvent ?. event . Properties ?. Payload ,
139
+ }
140
+
141
+ samDebugConfig = createApiAwsSamDebugConfig (
142
+ workspaceFolder ,
143
+ runtimeName ,
144
+ resourceName ,
145
+ rootUri . fsPath ,
146
+ apiConfig
147
+ )
148
+ }
124
149
} else if ( type === CODE_TARGET_TYPE ) {
125
150
const quickPick = createRuntimeQuickPick ( {
126
151
showImageRuntimes : false ,
@@ -151,21 +176,6 @@ export async function addSamDebugConfiguration(
151
176
// User backed out of runtime selection. Abandon config creation.
152
177
return
153
178
}
154
- } else if ( type === API_TARGET_TYPE ) {
155
- // If the event has no properties, the default will be used
156
- const preloadedConfig = {
157
- path : apiEvent ?. event . Properties ?. Path ,
158
- httpMethod : apiEvent ?. event . Properties ?. Method ,
159
- payload : apiEvent ?. event . Properties ?. Payload ,
160
- }
161
-
162
- samDebugConfig = createApiAwsSamDebugConfig (
163
- workspaceFolder ,
164
- runtimeName ,
165
- resourceName ,
166
- rootUri . fsPath ,
167
- preloadedConfig
168
- )
169
179
} else {
170
180
throw new Error ( 'Unrecognized debug target type' )
171
181
}
0 commit comments