diff --git a/aws-b2bi-transformer/aws-b2bi-transformer.json b/aws-b2bi-transformer/aws-b2bi-transformer.json
index fe9ca7d..b797e57 100644
--- a/aws-b2bi-transformer/aws-b2bi-transformer.json
+++ b/aws-b2bi-transformer/aws-b2bi-transformer.json
@@ -166,6 +166,7 @@
],
"readOnlyProperties": [
"/properties/CreatedAt",
+ "/properties/ModifiedAt",
"/properties/TransformerArn",
"/properties/TransformerId"
],
@@ -177,6 +178,7 @@
"permissions": [
"b2bi:CreateTransformer",
"b2bi:TagResource",
+ "b2bi:UpdateTransformer",
"logs:CreateLogDelivery",
"logs:CreateLogGroup",
"logs:CreateLogStream",
@@ -190,8 +192,8 @@
},
"read": {
"permissions": [
- "b2bi:ListTagsForResource",
- "b2bi:GetTransformer"
+ "b2bi:GetTransformer",
+ "b2bi:ListTagsForResource"
]
},
"update": {
diff --git a/aws-b2bi-transformer/docs/README.md b/aws-b2bi-transformer/docs/README.md
index e87494e..9ff5425 100644
--- a/aws-b2bi-transformer/docs/README.md
+++ b/aws-b2bi-transformer/docs/README.md
@@ -15,7 +15,6 @@ To declare this entity in your AWS CloudFormation template, use the following sy
"EdiType" : EdiType,
"FileFormat" : String,
"MappingTemplate" : String,
- "ModifiedAt" : String,
"Name" : String,
"SampleDocument" : String,
"Status" : String,
@@ -32,7 +31,6 @@ Properties:
EdiType: EdiType
FileFormat: String
MappingTemplate: String
- ModifiedAt: String
Name: String
SampleDocument: String
Status: String
@@ -70,14 +68,6 @@ _Maximum Length_: 350000
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
-#### ModifiedAt
-
-_Required_: No
-
-_Type_: String
-
-_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
-
#### Name
_Required_: Yes
@@ -134,6 +124,10 @@ For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::G
Returns the CreatedAt
value.
+#### ModifiedAt
+
+Returns the ModifiedAt
value.
+
#### TransformerArn
Returns the TransformerArn
value.
diff --git a/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/CreateHandler.kt b/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/CreateHandler.kt
index e8cb00f..92eb300 100644
--- a/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/CreateHandler.kt
+++ b/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/CreateHandler.kt
@@ -5,6 +5,8 @@ import software.amazon.cloudformation.proxy.*
import software.amazon.awssdk.services.b2bi.B2BiClient
import software.amazon.awssdk.services.b2bi.model.CreateTransformerRequest
import software.amazon.awssdk.services.b2bi.model.CreateTransformerResponse
+import software.amazon.awssdk.services.b2bi.model.TransformerStatus
+import software.amazon.awssdk.services.b2bi.model.UpdateTransformerRequest
import software.amazon.b2bi.transformer.TagHelper.convertToList
import software.amazon.b2bi.transformer.TagHelper.getNewDesiredTags
import software.amazon.b2bi.transformer.Translator.toCfnException
@@ -30,10 +32,12 @@ class CreateHandler : BaseHandlerStd() {
proxy.initiate(OPERATION, proxyClient, progress.resourceModel, progress.callbackContext)
.translateToServiceRequest(Translator::translateToCreateRequest)
.makeServiceCall { awsRequest, client -> createTransformer(awsRequest, client, resourceModel) }
+ .stabilize { _, _, client, resourceModel, _ -> stabilizeTransformer(resourceModel, client) }
.progress()
}
.then { progress -> ProgressEvent.defaultSuccessHandler(progress.resourceModel) }
}
+
private fun createTransformer(
request: CreateTransformerRequest,
proxyClient: ProxyClient,
@@ -48,12 +52,35 @@ class CreateHandler : BaseHandlerStd() {
transformerId = response.transformerId()
transformerArn = response.transformerArn()
createdAt = response.createdAt().toString()
- status = response.status().toString()
}
logger.log("Successfully created ${ResourceModel.TYPE_NAME} ${resourceModel.transformerId}")
return response
}
+ private fun stabilizeTransformer(
+ resourceModel: ResourceModel,
+ proxyClient: ProxyClient,
+ ): Boolean {
+ val requestedTransformerStatus = resourceModel.status
+ if (requestedTransformerStatus != TransformerStatus.ACTIVE.toString()) {
+ resourceModel.apply {
+ status = TransformerStatus.INACTIVE.toString()
+ }
+ return true
+ }
+
+ val updateTransformerRequest = Translator.translateToUpdateRequest(resourceModel)
+ val updateTransformerResponse = try {
+ proxyClient.injectCredentialsAndInvokeV2(updateTransformerRequest, proxyClient.client()::updateTransformer)
+ } catch (e: AwsServiceException) {
+ throw e.toCfnException()
+ }
+ resourceModel.apply {
+ status = updateTransformerResponse.statusAsString()
+ }
+ return true
+ }
+
companion object {
private const val OPERATION = "AWS-B2BI-Transformer::Create"
}
diff --git a/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/Translator.kt b/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/Translator.kt
index f281a44..a88f598 100644
--- a/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/Translator.kt
+++ b/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/Translator.kt
@@ -1,21 +1,36 @@
package software.amazon.b2bi.transformer
-import com.google.common.collect.Lists
-import software.amazon.awssdk.awscore.AwsRequest
-import software.amazon.awssdk.awscore.AwsResponse
import software.amazon.awssdk.awscore.exception.AwsServiceException
-import software.amazon.awssdk.services.b2bi.model.*
+import software.amazon.awssdk.services.b2bi.model.AccessDeniedException
+import software.amazon.awssdk.services.b2bi.model.ConflictException
+import software.amazon.awssdk.services.b2bi.model.CreateTransformerRequest
+import software.amazon.awssdk.services.b2bi.model.DeleteTransformerRequest
+import software.amazon.awssdk.services.b2bi.model.GetTransformerRequest
+import software.amazon.awssdk.services.b2bi.model.GetTransformerResponse
+import software.amazon.awssdk.services.b2bi.model.InternalServerException
+import software.amazon.awssdk.services.b2bi.model.ListTransformersRequest
+import software.amazon.awssdk.services.b2bi.model.ListTransformersResponse
import software.amazon.awssdk.services.b2bi.model.ResourceNotFoundException
-import software.amazon.awssdk.services.b2bi.model.X12Details
+import software.amazon.awssdk.services.b2bi.model.ServiceQuotaExceededException
+import software.amazon.awssdk.services.b2bi.model.TagResourceRequest
+import software.amazon.awssdk.services.b2bi.model.ThrottlingException
+import software.amazon.awssdk.services.b2bi.model.UntagResourceRequest
+import software.amazon.awssdk.services.b2bi.model.UpdateTransformerRequest
+import software.amazon.awssdk.services.b2bi.model.ValidationException
import software.amazon.b2bi.transformer.TagHelper.toSdkTag
-import software.amazon.cloudformation.exceptions.*
-import java.util.*
-import java.util.stream.Collectors
-import java.util.stream.Stream
-import software.amazon.b2bi.transformer.EdiType as ResourceEdi
+import software.amazon.cloudformation.exceptions.BaseHandlerException
+import software.amazon.cloudformation.exceptions.CfnAccessDeniedException
+import software.amazon.cloudformation.exceptions.CfnAlreadyExistsException
+import software.amazon.cloudformation.exceptions.CfnGeneralServiceException
+import software.amazon.cloudformation.exceptions.CfnInvalidRequestException
+import software.amazon.cloudformation.exceptions.CfnNotFoundException
+import software.amazon.cloudformation.exceptions.CfnServiceInternalErrorException
+import software.amazon.cloudformation.exceptions.CfnServiceLimitExceededException
+import software.amazon.cloudformation.exceptions.CfnThrottlingException
import software.amazon.awssdk.services.b2bi.model.EdiType as SdkEdi
-import software.amazon.b2bi.transformer.X12Details as ResourceX12
import software.amazon.awssdk.services.b2bi.model.X12Details as SdkX12
+import software.amazon.b2bi.transformer.EdiType as ResourceEdi
+import software.amazon.b2bi.transformer.X12Details as ResourceX12
/**
* This class is a centralized placeholder for
@@ -53,7 +68,7 @@ object Translator {
/**
* Translates resource object from sdk into a resource model
- * @param awsResponse the aws service describe resource response
+ * @param response the aws service describe resource response
* @return model resource model
*/
fun translateFromReadResponse(response: GetTransformerResponse): ResourceModel {
@@ -114,7 +129,7 @@ object Translator {
/**
* Translates resource objects from sdk into a resource model (primary identifier only)
- * @param awsResponse the aws service describe resource response
+ * @param response the aws service describe resource response
* @return list of resource models
*/
fun translateFromListResponse(response: ListTransformersResponse): List {
diff --git a/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/UpdateHandler.kt b/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/UpdateHandler.kt
index ea3d392..f2c3767 100644
--- a/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/UpdateHandler.kt
+++ b/aws-b2bi-transformer/src/main/kotlin/software/amazon/b2bi/transformer/UpdateHandler.kt
@@ -1,12 +1,9 @@
package software.amazon.b2bi.transformer
-import software.amazon.awssdk.awscore.AwsResponse
import software.amazon.awssdk.awscore.exception.AwsServiceException
-import software.amazon.awssdk.core.SdkClient
import software.amazon.awssdk.services.b2bi.B2BiClient
import software.amazon.awssdk.services.b2bi.model.UpdateTransformerRequest
import software.amazon.awssdk.services.b2bi.model.UpdateTransformerResponse
-import software.amazon.b2bi.transformer.Translator.translateToResourceEdi
import software.amazon.b2bi.transformer.TagHelper.convertToList
import software.amazon.b2bi.transformer.TagHelper.generateTagsToAdd
import software.amazon.b2bi.transformer.TagHelper.generateTagsToRemove
@@ -16,8 +13,12 @@ import software.amazon.b2bi.transformer.TagHelper.shouldUpdateTags
import software.amazon.b2bi.transformer.TagHelper.tagResource
import software.amazon.b2bi.transformer.TagHelper.untagResource
import software.amazon.b2bi.transformer.Translator.toCfnException
-import software.amazon.cloudformation.exceptions.CfnGeneralServiceException
-import software.amazon.cloudformation.proxy.*
+import software.amazon.b2bi.transformer.Translator.translateToResourceEdi
+import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy
+import software.amazon.cloudformation.proxy.Logger
+import software.amazon.cloudformation.proxy.ProgressEvent
+import software.amazon.cloudformation.proxy.ProxyClient
+import software.amazon.cloudformation.proxy.ResourceHandlerRequest
class UpdateHandler : BaseHandlerStd() {
private lateinit var logger: Logger
@@ -94,5 +95,4 @@ class UpdateHandler : BaseHandlerStd() {
companion object {
private const val OPERATION = "AWS-B2BI-Transformer::Update"
}
-
}
diff --git a/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/CreateHandlerTest.kt b/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/CreateHandlerTest.kt
index 464904e..a1b48e9 100644
--- a/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/CreateHandlerTest.kt
+++ b/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/CreateHandlerTest.kt
@@ -38,6 +38,7 @@ class CreateHandlerTest : AbstractTestBase() {
proxyClient = mockProxy(proxy, b2BiClient)
}
+ @AfterEach
fun reset() {
clearAllMocks()
}
diff --git a/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/TestData.kt b/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/TestData.kt
index 760e6ed..43d41ed 100644
--- a/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/TestData.kt
+++ b/aws-b2bi-transformer/src/test/kotlin/software/amazon/b2bi/transformer/TestData.kt
@@ -6,6 +6,7 @@ import software.amazon.awssdk.services.b2bi.model.GetTransformerResponse
import software.amazon.awssdk.services.b2bi.model.ListTransformersResponse
import software.amazon.awssdk.services.b2bi.model.ListTagsForResourceResponse
import software.amazon.awssdk.services.b2bi.model.Logging
+import software.amazon.awssdk.services.b2bi.model.TransformerStatus
import software.amazon.awssdk.services.b2bi.model.TransformerSummary
import software.amazon.awssdk.services.b2bi.model.UpdateTransformerResponse
import software.amazon.b2bi.transformer.TagHelper.toSdkTag
@@ -22,7 +23,7 @@ val TEST_X12: X12Details = X12Details.builder().transactionSet(TEST_TRANSACTION_
const val TEST_NAME = "Test transformer name"
const val TEST_FILE_FORMAT = "JSON"
const val TEST_MAPPING_TEMPLATE = "test mapping template"
-const val TEST_TRANSFORMER_STATUS = "active"
+val TEST_TRANSFORMER_STATUS = TransformerStatus.INACTIVE.toString()
val TEST_RESOURCE_EDI_TYPE: EdiType = EdiType.builder().x12Details(TEST_X12).build()
val TEST_SDK_EDI_TYPE = TEST_RESOURCE_EDI_TYPE.translateToSdkEdi()
const val TEST_TRANSFORMER_ID = "t-12345678901234567"
@@ -48,6 +49,7 @@ val TEST_CREATE_TRANSFORMER_REQUEST_RESOURCE_MODEL_WITH_REQUIRED_FIELDS = Resour
.fileFormat(TEST_FILE_FORMAT)
.mappingTemplate(TEST_MAPPING_TEMPLATE)
.ediType(TEST_RESOURCE_EDI_TYPE)
+ .status(TEST_TRANSFORMER_STATUS)
.tags(emptyList())
.createdAt(TEST_INSTANT.toString())
.modifiedAt(TEST_INSTANT.toString())
@@ -177,4 +179,4 @@ val TEST_UPDATE_TRANSFORMER_RESPONSE_RESOURCE_MODEL_WITH_ALL_FIELDS = ResourceMo
.fileFormat(TEST_FILE_FORMAT)
.status(TEST_TRANSFORMER_STATUS)
.tags(emptyList())
- .build()
\ No newline at end of file
+ .build()