@@ -194,17 +194,19 @@ Dry run mode is only available within:
194
194
You can import cloud-nuke into other projects and use it as a library for programmatically inspecting and counting resources.
195
195
196
196
``` golang
197
+
197
198
package main
198
199
199
200
import (
200
201
" fmt"
201
202
" time"
202
203
204
+ " github.com/aws/aws-sdk-go/aws"
203
205
nuke_aws " github.com/gruntwork-io/cloud-nuke/aws"
206
+ " github.com/gruntwork-io/cloud-nuke/externalcreds"
204
207
)
205
208
206
209
func main () {
207
-
208
210
// You can scan multiple regions at once, or just pass a single region for speed
209
211
targetRegions := []string {" us-east-1" , " us-west-1" , " us-west-2" }
210
212
excludeRegions := []string {}
@@ -214,6 +216,17 @@ func main() {
214
216
// excludeAfter is parsed identically to the --older-than flag
215
217
excludeAfter := time.Now ()
216
218
219
+ // Any custom settings you want
220
+ myCustomConfig := &aws.Config {}
221
+
222
+ myCustomConfig.WithMaxRetries (3 )
223
+ myCustomConfig.WithLogLevel (aws.LogDebugWithRequestErrors )
224
+ // Optionally, set custom credentials
225
+ // myCustomConfig.WithCredentials()
226
+
227
+ // Be sure to set your config prior to calling any library methods such as NewQuery
228
+ externalcreds.Set (myCustomConfig)
229
+
217
230
// NewQuery is a convenience method for configuring parameters you want to pass to your resource search
218
231
query , err := nuke_aws.NewQuery (
219
232
targetRegions,
@@ -222,7 +235,6 @@ func main() {
222
235
excludeResourceTypes,
223
236
excludeAfter,
224
237
)
225
-
226
238
if err != nil {
227
239
fmt.Println (err)
228
240
}
@@ -246,15 +258,14 @@ func main() {
246
258
// countOfEc2InUsWest1: 2
247
259
248
260
fmt.Printf (" usWest1Resources.ResourceTypePresent(\" ec2\" ):%b \n " , usWest1Resources.ResourceTypePresent (" ec2" ))
249
- // usWest1Resources.ResourceTypePresent("ec2"): true
261
+ // usWest1Resources.ResourceTypePresent("ec2"): true
250
262
251
263
// Get all the resource identifiers for a given resource type
252
264
// In this example, we're only looking for ec2 instances
253
265
resourceIds := usWest1Resources.IdentifiersForResourceType (" ec2" )
254
266
255
267
fmt.Printf (" resourceIds: %s " , resourceIds)
256
268
// resourceIds: [i-0c5d16c3ef28dda24 i-09d9739e1f4d27814]
257
-
258
269
}
259
270
```
260
271
0 commit comments