Python Code

duplicateWAFR.py

The purpose of this python script is to duplicate a Well-Architected Workload review. This can be done within the same account but to a new AWS Region, or it can be done to a different AWS account and/or region. During the copy process, it will generate a new workload in the target account with the same Workload Name, but the workloadId will be unique. If the target workload already exists, the script will prompt the user if they wish to refresh the data from the source workload.

This utility was created using the the AWS SDK for Python (Boto3). This file assumes you have already setup your AWS credential file, and uses the default profile for all interactions.

There is error checking for most of the various API calls, but the code should not be considered production ready. Please review before implementing in your environment.

Parameters

usage: duplicateWAFR.py [-h] [--fromaccount FROMACCOUNT] [--toaccount TOACCOUNT] --workloadid WORKLOADID [--fromregion FROMREGION] [--toregion TOREGION]

optional arguments:
  -h, --help                show this help message and exit
  --fromaccount FROMACCOUNT AWS CLI Profile Name or will use the default session for the shell
  --toaccount TOACCOUNT     AWS CLI Profile Name or will use the default session for the shell
  --workloadid WORKLOADID   WorkloadID. Example: 1e5d148ab9744e98343cc9c677a34682
  --fromregion FROMREGION   From Region Name. Example: us-east-1
  --toregion TOREGION       To Region Name. Example: us-east-2

Limitations

  1. The code has been tested against multiple accounts, but it does not include full error handling for all situations. Please limit the use to interactive sessions at this time.
  2. Because this is simply copying the data to a new WA review in the target account, the target workloadId will be different.
  3. This will not copy any of the Workload Sharing features to the target workload.
  4. If a Workload exists in the target account with the same name, the script will just attempt to update the review with the data from the source, not create a new one.

Python Code

Link to download the code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
#!/usr/bin/env python3

# This is a tool to copy a WA Framework Review from one account to another
# It can also be used to copy between regions for the same account
#
# This code is only for use in Well-Architected labs
# *** NOT FOR PRODUCTION USE ***
#
# Licensed under the Apache 2.0 and MITnoAttr License.
#
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
# https://aws.amazon.com/apache2.0/

import botocore
import boto3
import json
import datetime
import logging
import jmespath
import base64
import argparse
from pkg_resources import packaging


__author__    = "Eric Pullen"
__email__     = "eppullen@amazon.com"
__copyright__ = "Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved."
__credits__   = ["Eric Pullen"]

# Default region listed here
REGION_NAME = "us-east-1"
blankjson = {}
response = ""

# Setup Logging
logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S',
)

logger = logging.getLogger()
logging.getLogger('boto3').setLevel(logging.CRITICAL)
logging.getLogger('botocore').setLevel(logging.CRITICAL)
logging.getLogger('s3transfer').setLevel(logging.CRITICAL)
logging.getLogger('urllib3').setLevel(logging.CRITICAL)

PARSER = argparse.ArgumentParser()
PARSER.add_argument('--fromaccount', required=False, default="", help='AWS CLI Profile Name or will use the default session for the shell')
PARSER.add_argument('--toaccount', required=False, default="", help='AWS CLI Profile Name or will use the default session for the shell')
PARSER.add_argument('--workloadid', required=True, help='WorkloadID. Example: 1e5d148ab9744e98343cc9c677a34682')
PARSER.add_argument('--fromregion', required=False, default="us-east-1", help='From Region Name. Example: us-east-1')
PARSER.add_argument('--toregion', required=False, default="us-east-1", help='To Region Name. Example: us-east-2')
ARGUMENTS = PARSER.parse_args()

REGION_NAME = ARGUMENTS.fromregion
TO_REGION_NAME = ARGUMENTS.toregion
FROM_ACCOUNT = ARGUMENTS.fromaccount
TO_ACCOUNT = ARGUMENTS.toaccount
FROM_WORKLOADID = ARGUMENTS.workloadid

# Helper class to convert a datetime item to JSON.
class DateTimeEncoder(json.JSONEncoder):
    def default(self, z):
        if isinstance(z, datetime.datetime):
            return (str(z))
        else:
            return super().default(z)

def CreateNewWorkload(
    waclient,
    workloadName,
    description,
    reviewOwner,
    environment,
    awsRegions,
    lenses,
    tags,
    pillarPriorities,
    notes="",
    nonAwsRegions=[],
    architecturalDesign='',
    industryType='',
    industry='',
    accountIds=[]
    ):
    # Create your workload
    try:
        response=waclient.create_workload(
        WorkloadName=workloadName,
        Description=description,
        ReviewOwner=reviewOwner,
        Environment=environment,
        AwsRegions=awsRegions,
        Lenses=lenses,
        NonAwsRegions=nonAwsRegions,
        PillarPriorities=pillarPriorities,
        ArchitecturalDesign=architecturalDesign,
        IndustryType=industryType,
        Industry=industry,
        Notes=notes,
        AccountIds=accountIds
        )
    except waclient.exceptions.ConflictException as e:
        workloadId,workloadARN = FindWorkload(waclient,workloadName)
        logger.error("ERROR - The workload name %s already exists as workloadId %s" % (workloadName, workloadId))
        userAnswer=input("Do You Want To Overwrite workload %s? [y/n]" % workloadId)
        if userAnswer == "y":
            logger.info("Overwriting existing workload")
            UpdateWorkload(waclient,workloadId,workloadARN, workloadName,description,reviewOwner,environment,awsRegions,lenses,tags)
        else:
            logger.error("Exiting due to duplicate workload and user states they do not want to continue.")
            exit(1)
        return workloadId, workloadARN
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    workloadId = response['WorkloadId']
    workloadARN = response['WorkloadArn']
    return workloadId, workloadARN

def UpdateWorkload(
    waclient,
    workloadId,
    workloadARN,
    workloadName,
    description,
    reviewOwner,
    environment,
    awsRegions,
    lenses,
    tags
    ):

    logger.info("Updating workload properties")
    # Create your workload
    try:
        waclient.update_workload(
        WorkloadId=workloadId,
        WorkloadName=workloadName,
        Description=description,
        ReviewOwner=reviewOwner,
        Environment=environment,
        AwsRegions=awsRegions,
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)
    # Should add updates for the lenses?
    # Should add the tags as well
    if tags:
        logger.info("Updating workload tags")
        try:
            waclient.tag_resource(WorkloadArn=workloadARN,Tags=tags)
        except botocore.exceptions.ParamValidationError as e:
            logger.error("ERROR - Parameter validation error: %s" % e)
        except botocore.exceptions.ClientError as e:
            logger.error("ERROR - Unexpected error: %s" % e)
    else:
        logger.info("Found blank tag set, removing any I find")
        try:
            tagresponse = waclient.list_tags_for_resource(WorkloadArn=workloadARN)
        except botocore.exceptions.ParamValidationError as e:
            logger.error("ERROR - Parameter validation error: %s" % e)
        except botocore.exceptions.ClientError as e:
            logger.error("ERROR - Unexpected error: %s" % e)
        tagkeys = list(tagresponse['Tags'])
        if tagkeys:
            try:
                waclient.untag_resource(WorkloadArn=workloadARN,TagKeys=tagkeys)
            except botocore.exceptions.ParamValidationError as e:
                logger.error("ERROR - Parameter validation error: %s" % e)
            except botocore.exceptions.ClientError as e:
                logger.error("ERROR - Unexpected error: %s" % e)
        else:
            logger.info("TO Workload has blank keys as well, no need to update")



def FindWorkload(
    waclient,
    workloadName
    ):
    # Finding your WorkloadId
    try:
        response=waclient.list_workloads(
        WorkloadNamePrefix=workloadName
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print("Full JSON:",json.dumps(response['WorkloadSummaries'], cls=DateTimeEncoder))
    workloadId = response['WorkloadSummaries'][0]['WorkloadId']
    workloadArn = response['WorkloadSummaries'][0]['WorkloadArn']
    # print("WorkloadId",workloadId)
    return workloadId, workloadArn

def DeleteWorkload(
    waclient,
    workloadId
    ):

    # Delete the WorkloadId
    try:
        response=waclient.delete_workload(
        WorkloadId=workloadId
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

def GetWorkload(
    waclient,
    workloadId
    ):

    # Get the WorkloadId
    try:
        response=waclient.get_workload(
        WorkloadId=workloadId
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)
        exit()

    # print("Full JSON:",json.dumps(response['Workload'], cls=DateTimeEncoder))
    workload = response['Workload']
    # print("WorkloadId",workloadId)
    return workload

def disassociateLens(
    waclient,
    workloadId,
    lens
    ):

    # Disassociate the lens from the WorkloadId
    try:
        response=waclient.disassociate_lenses(
        WorkloadId=workloadId,
        LensAliases=lens
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

def associateLens(
    waclient,
    workloadId,
    lens
    ):

    # Associate the lens from the WorkloadId
    try:
        response=waclient.associate_lenses(
        WorkloadId=workloadId,
        LensAliases=lens
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)


def listLens(
    waclient
    ):

    # List all lenses currently available
    try:
        response=waclient.list_lenses()
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print(json.dumps(response))
    lenses = jmespath.search("LensSummaries[*].LensAlias", response)

    return lenses

def findQuestionId(
    waclient,
    workloadId,
    lensAlias,
    pillarId,
    questionTitle
    ):

    # Find a questionID using the questionTitle
    try:
        response=waclient.list_answers(
        WorkloadId=workloadId,
        LensAlias=lensAlias,
        PillarId=pillarId
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    answers = response['AnswerSummaries']
    while "NextToken" in response:
        response = waclient.list_answers(WorkloadId=workloadId,LensAlias=lensAlias,PillarId=pillarId,NextToken=response["NextToken"])
        answers.extend(response["AnswerSummaries"])

    jmesquery = "[?starts_with(QuestionTitle, `"+questionTitle+"`) == `true`].QuestionId"
    questionId = jmespath.search(jmesquery, answers)

    return questionId[0]

def findChoiceId(
    waclient,
    workloadId,
    lensAlias,
    questionId,
    choiceTitle,
    ):

    # Find a choiceId using the choiceTitle
    try:
        response=waclient.get_answer(
        WorkloadId=workloadId,
        LensAlias=lensAlias,
        QuestionId=questionId
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    jmesquery = "Answer.Choices[?starts_with(Title, `"+choiceTitle+"`) == `true`].ChoiceId"
    choiceId = jmespath.search(jmesquery, response)

    return choiceId[0]

def getAnswersForQuestion(
    waclient,
    workloadId,
    lensAlias,
    questionId
    ):

    # Find a answer for a questionId
    try:
        response=waclient.get_answer(
        WorkloadId=workloadId,
        LensAlias=lensAlias,
        QuestionId=questionId
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print(json.dumps(response))
    jmesquery = "Answer.SelectedChoices"
    answers = jmespath.search(jmesquery, response)
    # print(answers)
    return answers

def getNotesForQuestion(
    waclient,
    workloadId,
    lensAlias,
    questionId
    ):

    # Find a answer for a questionId
    try:
        response=waclient.get_answer(
        WorkloadId=workloadId,
        LensAlias=lensAlias,
        QuestionId=questionId
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print(json.dumps(response))
    # jmesquery = "Answer.Notes"
    # answers = jmespath.search(jmesquery, response)
    response = response['Answer']
    answers = response['Notes'] if "Notes" in response else ""

    # print(answers)
    return answers

def updateAnswersForQuestion(
    waclient,
    workloadId,
    lensAlias,
    questionId,
    selectedChoices,
    notes
    ):

    # Update a answer to a question
    try:
        response=waclient.update_answer(
        WorkloadId=workloadId,
        LensAlias=lensAlias,
        QuestionId=questionId,
        SelectedChoices=selectedChoices,
        Notes=notes
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print(json.dumps(response))
    jmesquery = "Answer.SelectedChoices"
    answers = jmespath.search(jmesquery, response)
    return answers

def listMilestones(
    waclient,
    workloadId
    ):

    # Find a milestone for a workloadId
    try:
        response=waclient.list_milestones(
        WorkloadId=workloadId,
        MaxResults=50 # Need to check why I am having to pass this parameter
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)
    # print("Full JSON:",json.dumps(response['MilestoneSummaries'], cls=DateTimeEncoder))
    milestoneNumber = response['MilestoneSummaries']
    return milestoneNumber

def createMilestone(
    waclient,
    workloadId,
    milestoneName
    ):

    # Create a new milestone with milestoneName
    try:
        response=waclient.create_milestone(
        WorkloadId=workloadId,
        MilestoneName=milestoneName
        )
    except waclient.exceptions.ConflictException as e:
        milestones = listMilestones(waclient,workloadId)
        jmesquery = "[?starts_with(MilestoneName,`"+milestoneName+"`) == `true`].MilestoneNumber"
        milestoneNumber = jmespath.search(jmesquery,milestones)
        logger.error("ERROR - The milestone name %s already exists as milestone %s" % (milestoneName, milestoneNumber))
        return milestoneNumber[0]
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print("Full JSON:",json.dumps(response['MilestoneSummaries'], cls=DateTimeEncoder))
    milestoneNumber = response['MilestoneNumber']
    return milestoneNumber

def getMilestone(
    waclient,
    workloadId,
    milestoneNumber
    ):

    # Use get_milestone to return the milestone structure
    try:
        response=waclient.get_milestone(
        WorkloadId=workloadId,
        MilestoneNumber=milestoneNumber
        )
    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print("Full JSON:",json.dumps(response['Milestone'], cls=DateTimeEncoder))
    milestoneResponse = response['Milestone']
    return milestoneResponse

def getMilestoneRiskCounts(
    waclient,
    workloadId,
    milestoneNumber
    ):

    # Return just the RiskCount for a particular milestoneNumber

    milestone = getMilestone(waclient,workloadId,milestoneNumber)
    # print("Full JSON:",json.dumps(milestone['Workload']['RiskCounts'], cls=DateTimeEncoder))
    milestoneRiskCounts = milestone['Workload']['RiskCounts']
    return milestoneRiskCounts

def listAllAnswers(
    waclient,
    workloadId,
    lensAlias,
    milestoneNumber=""
    ):

    # Get a list of all answers
    try:
        if milestoneNumber:
            response=waclient.list_answers(
            WorkloadId=workloadId,
            LensAlias=lensAlias,
            MilestoneNumber=milestoneNumber
            )
        else:
            response=waclient.list_answers(
            WorkloadId=workloadId,
            LensAlias=lensAlias
            )

    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    answers = response['AnswerSummaries']
    while "NextToken" in response:
        if milestoneNumber:
            response = waclient.list_answers(WorkloadId=workloadId,LensAlias=lensAlias,MilestoneNumber=milestoneNumber,NextToken=response["NextToken"])
        else:
            response = waclient.list_answers(WorkloadId=workloadId,LensAlias=lensAlias,NextToken=response["NextToken"])
        answers.extend(response["AnswerSummaries"])

    # print("Full JSON:",json.dumps(answers, cls=DateTimeEncoder))
    return answers

def getLensReview(
    waclient,
    workloadId,
    lensAlias,
    milestoneNumber=""
    ):

    # Use get_lens_review to return the lens review structure
    try:
        if milestoneNumber:
            response=waclient.get_lens_review(
            WorkloadId=workloadId,
            LensAlias=lensAlias,
            MilestoneNumber=milestoneNumber
            )
        else:
            response=waclient.get_lens_review(
            WorkloadId=workloadId,
            LensAlias=lensAlias
            )

    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print("Full JSON:",json.dumps(response['LensReview'], cls=DateTimeEncoder))
    lensReview = response['LensReview']
    return lensReview

def getLensReviewPDFReport(
    waclient,
    workloadId,
    lensAlias,
    milestoneNumber=""
    ):

    # Use get_lens_review_report to return the lens review PDF in base64 structure
    try:
        if milestoneNumber:
            response=waclient.get_lens_review_report(
            WorkloadId=workloadId,
            LensAlias=lensAlias,
            MilestoneNumber=milestoneNumber
            )
        else:
            response=waclient.get_lens_review_report(
            WorkloadId=workloadId,
            LensAlias=lensAlias
            )

    except botocore.exceptions.ParamValidationError as e:
        logger.error("ERROR - Parameter validation error: %s" % e)
    except botocore.exceptions.ClientError as e:
        logger.error("ERROR - Unexpected error: %s" % e)

    # print("Full JSON:",json.dumps(response['LensReviewReport']['Base64String'], cls=DateTimeEncoder))
    lensReviewPDF = response['LensReviewReport']['Base64String']
    return lensReviewPDF

def main():
    boto3_min_version = "1.16.38"
    # Verify if the version of Boto3 we are running has the wellarchitected APIs included
    if (packaging.version.parse(boto3.__version__) < packaging.version.parse(boto3_min_version)):
        logger.error("Your Boto3 version (%s) is less than %s. You must ugprade to run this script (pip3 install boto3 --upgrade --user)" % (boto3.__version__, boto3_min_version))
        exit()

    # STEP 1 - Configure environment
    logger.info("Starting Boto %s Session" % boto3.__version__)
    # Create a new boto3 session
    if FROM_ACCOUNT:
        SESSION1 = boto3.session.Session(profile_name=FROM_ACCOUNT)
    else:
        SESSION1 = boto3.session.Session()
    if TO_ACCOUNT:
        SESSION2 = boto3.session.Session(profile_name=TO_ACCOUNT)
    else:
        SESSION2 = boto3.session.Session()
    # Initiate the well-architected session using the region defined above
    WACLIENT = SESSION1.client(
        service_name='wellarchitected',
        region_name=REGION_NAME,
    )

    WACLIENT_TO = SESSION2.client(
        service_name='wellarchitected',
        region_name=TO_REGION_NAME,
    )



    logger.info("Copy WorkloadID '%s' from '%s:%s' to '%s:%s'" % (FROM_WORKLOADID,REGION_NAME,FROM_ACCOUNT,TO_REGION_NAME,TO_ACCOUNT))
    # Ignoring milestones for now, will add later if interested
    workloadId = FROM_WORKLOADID
    # Find out what lenses apply to the from workloadid
    workloadJson = GetWorkload(WACLIENT,workloadId)
    WorkloadARN = workloadJson['WorkloadArn']
    # For each of the optional variables, lets check and see if we have them first:
    Notes = workloadJson['Notes'] if "Notes" in workloadJson else ""
    nonAwsRegions = workloadJson['NonAwsRegions'] if "NonAwsRegions" in workloadJson else []
    architecturalDesign = workloadJson['ArchitecturalDesign'] if "ArchitecturalDesign" in workloadJson else ""
    industryType = workloadJson['IndustryType'] if "IndustryType" in workloadJson else ""
    industry = workloadJson['Industry'] if "Industry" in workloadJson else ""
    accountIds = workloadJson['AccountIds'] if "AccountIds" in workloadJson else []
    tagresponse = WACLIENT.list_tags_for_resource(WorkloadArn=WorkloadARN)
    tags = tagresponse['Tags'] if "Tags" in tagresponse else []

    # Create the new workload to copy into
    toWorkloadId,toWorkloadARN = CreateNewWorkload(WACLIENT_TO,
    (workloadJson['WorkloadName']),
    workloadJson['Description'],
    workloadJson['ReviewOwner'],
    workloadJson['Environment'],
    workloadJson['AwsRegions'],
    workloadJson['Lenses'],
    tags,
    workloadJson['PillarPriorities'],
    Notes,
    nonAwsRegions,
    architecturalDesign,
    industryType,
    industry,
    accountIds
    )
    logger.info("New workload id: %s (%s)" % (toWorkloadId,toWorkloadARN))

    # Iterate over each lens and copy all of the answers
    for lens in workloadJson['Lenses']:
        logger.info("Retrieving all answers for lens %s" % lens)
        answers = listAllAnswers(WACLIENT,workloadId,lens)
        # Ensure the lens is attached to the new workload
        associateLens(WACLIENT_TO,toWorkloadId,[lens])
        logger.info("Copying answers into new workload for lens %s" % lens)
        for answerCopy in answers:
            notesField = ''
            notesField = getNotesForQuestion(WACLIENT,workloadId,lens,answerCopy['QuestionId'])
            updateAnswersForQuestion(WACLIENT_TO,toWorkloadId,lens,answerCopy['QuestionId'],answerCopy['SelectedChoices'],notesField)

    logger.info("Copy complete - exiting")


if __name__ == "__main__":
    main()