0
votes

I have 2 templates those I have taken from the AWS::Athena::WorkGroup - AWS CloudFormation documentation.

The first template athena_create.yaml works as expected. The second template needs to modify the workgroup created in the first template. But I get an error:

MyCustomWorkGroup already exists in stack arn:aws:cloudformation:us-east-1:XXX:stack/a1/7cc670a0-8d19-11ea-872c-12217e59f19f

Here is the code. create template works correctly.

athena_create.yaml

Resources:
  MyAthenaWorkGroup:
    Type: AWS::Athena::WorkGroup
    Properties:
      Name: MyCustomWorkGroup
      Description: My WorkGroup
      State: ENABLED
      Tags:
        - Key: "key1"
          Value: "value1"
        - Key: "key2"
          Value: "value2"
      WorkGroupConfiguration:
        BytesScannedCutoffPerQuery: 200000000
        EnforceWorkGroupConfiguration: false
        PublishCloudWatchMetricsEnabled: false
        RequesterPaysEnabled: true
        ResultConfiguration:
          OutputLocation: s3://path/to/my/bucket/

athena_update.yaml

Resources:
  MyAthenaWorkGroup:
    Type: AWS::Athena::WorkGroup
    Properties:
      Name: MyCustomWorkGroup
      Description: My WorkGroup Updated
      State: DISABLED
      Tags:
        - Key: "key1"
          Value: "value1"
        - Key: "key2"
          Value: "value2"
      WorkGroupConfigurationUpdates:
        BytesScannedCutoffPerQuery: 10000000
        EnforceWorkGroupConfiguration: true
        PublishCloudWatchMetricsEnabled: true
        RequesterPaysEnabled: false
        ResultConfigurationUpdates:
          EncryptionConfiguration:
            EncryptionOption: SSE_S3
          OutputLocation: s3://path/to/my/bucket/updated/

The update template mentioned above does not work as expected.

1
I guess you are deploying them as two separate templates? In that case you can't do this because the two templates create two WorkGroups of same Name: MyCustomWorkGroup .Marcin
How do I update a workgroup using cloudformation template?shantanuo
You create the stack using first template. Then once done, you go to the stack and click update. This will updated the orginal stack, instead of creating new one.Marcin
Thanks. Got it. Is there any way to update default workgroup using cloudformation?shantanuo
If you don't mind I will make an answer for future reference. Unfortunate not that familiar with Athena. Just new why CloudFormation was giving your problems.Marcin

1 Answers

1
votes

The reason for the error is that the two templates were used to create two independent stacks. This didn't work because they two Athena WorkGroups of same Name: MyCustomWorkGroup.

The correct way to perform create and update the MyCustomWorkGroup is as follows:

  1. Create a stack using athena_create.yaml file.

  2. Once the stack is created, use its Update option to upload athena_update.yaml which is going to update the stack.