private Environment createEnvironmentDDB(
      @NonNull final Environment environment, DynamoDBMapperConfig dynamoDBMapperConfig)
      throws ResourceExistsException, InternalServiceException {

    final EnvironmentDDBRecord environmentDDBRecord =
        environmentMapper.toEnvironmentDDBRecord(environment);

    try {
      dynamoDBMapper.save(environmentDDBRecord, dynamoDBMapperConfig);
    } catch (final ConditionalCheckFailedException e) {
      throw new ResourceExistsException(
          ResourceType.ENVIRONMENT, environment.getEnvironmentId().toString());

    } catch (final AmazonServiceException e) {
      throw new InternalServiceException(
          String.format(
              "Could not save record with environment id %s", environment.getEnvironmentId()),
          e);
    }

    return environmentMapper.toEnvironment(environmentDDBRecord);
  }
Create respecting optimistic locking. If an environment with specified keys exists or the item
has been updated after being retrieved, a conditional check exception will be thrown.
data-service/src/main/java/com/amazonaws/blox/dataservice/repository/EnvironmentRepositoryDDB.java