def tagAmi()

in imageCopier/src/main/scala/com/gu/imageCopier/AmiActions.scala [31:53]


  def tagAmi(amiEvent: AmiEvent, encryptedTagValue: String, newAmiId: String)(
      implicit ec2Client: Ec2Client
  ): Attempt[CreateTagsResponse] = {
    Attempt.catchNonFatal {
      val tags = amiEvent.tags ++ Map(
        "Encrypted" -> encryptedTagValue,
        "CopiedFromAMI" -> amiEvent.sourceAmi
      )
      val awsTags = tags.map { case (k, v) =>
        Tag.builder.key(k).value(v).build()
      }.toList
      val request = CreateTagsRequest.builder
        .resources(newAmiId)
        .tags(awsTags.asJava)
        .build()
      println(s"Creating tags with request $request")
      val response = ec2Client.createTags(request)
      println(s"Succeeded")
      response
    } { case ace: SdkServiceException =>
      AwsSdkFailure(ace)
    }
  }