1- /**
1+ /*
22 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License").
1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
16+
1617package com .amazon .aws .partners .saasfactory .saasboost ;
1718
1819import com .amazonaws .services .lambda .runtime .Context ;
3132
3233import java .io .ByteArrayOutputStream ;
3334import java .io .IOException ;
35+ import java .nio .charset .StandardCharsets ;
3436import java .util .*;
3537import java .util .stream .Collectors ;
3638import java .util .zip .ZipEntry ;
3739import java .util .zip .ZipOutputStream ;
3840
39- public class EcsDeploy implements RequestHandler <Map <String , Object >, Object > {
41+ public class WorkloadDeploy implements RequestHandler <Map <String , Object >, Object > {
4042
41- private final static Logger LOGGER = LoggerFactory .getLogger (EcsDeploy .class );
42- private final static String AWS_REGION = System .getenv ("AWS_REGION" );
43- private final static String SAAS_BOOST_ENV = System .getenv ("SAAS_BOOST_ENV" );
44- private final static String API_GATEWAY_HOST = System .getenv ("API_GATEWAY_HOST" );
45- private final static String API_GATEWAY_STAGE = System .getenv ("API_GATEWAY_STAGE" );
46- private final static String API_TRUST_ROLE = System .getenv ("API_TRUST_ROLE" );
43+ private static final Logger LOGGER = LoggerFactory .getLogger (WorkloadDeploy .class );
44+ private static final String AWS_REGION = System .getenv ("AWS_REGION" );
45+ private static final String SAAS_BOOST_ENV = System .getenv ("SAAS_BOOST_ENV" );
46+ private static final String API_GATEWAY_HOST = System .getenv ("API_GATEWAY_HOST" );
47+ private static final String API_GATEWAY_STAGE = System .getenv ("API_GATEWAY_STAGE" );
48+ private static final String API_TRUST_ROLE = System .getenv ("API_TRUST_ROLE" );
4749 private S3Client s3 ;
4850 private CodePipelineClient codepipeline ;
4951 private EcrClient ecr ;
5052 private String codePipelineBucket ;
5153
52- public EcsDeploy () {
53- long startTimeMillis = System .currentTimeMillis ();
54+ public WorkloadDeploy () {
55+ final long startTimeMillis = System .currentTimeMillis ();
5456 if (Utils .isBlank (AWS_REGION )) {
5557 throw new IllegalStateException ("Missing required environment variable AWS_REGION" );
5658 }
@@ -104,7 +106,7 @@ public EcsDeploy() {
104106 }
105107
106108 @ Override
107- public Object handleRequest (Map <String , Object > event , Context context ) {
109+ public Object handleRequest (Map <String , Object > event , Context context ) {
108110 Utils .logRequestEvent (event );
109111
110112 // Is this event an ECR image action or a first-time deploy custom event?
@@ -122,7 +124,7 @@ public Object handleRequest(Map<String, Object> event, Context context) {
122124 SdkHttpFullRequest getTenantsApiRequest = ApiGatewayHelper .getApiRequest (API_GATEWAY_HOST , API_GATEWAY_STAGE , provisionedTenants );
123125 LOGGER .info ("Fetching Provisioned tenants from tenants/provisioned" );
124126 try {
125- String functionName = "sb-" + SAAS_BOOST_ENV + "-workload-deploy-" + AWS_REGION ;
127+ String functionName = "sb-" + SAAS_BOOST_ENV + "-workload-deploy" ;
126128 String getTenantsResponseBody = ApiGatewayHelper .signAndExecuteApiRequest (getTenantsApiRequest , API_TRUST_ROLE , functionName );
127129 ArrayList <Map <String , Object >> getTenantsResponse = Utils .fromJson (getTenantsResponseBody , ArrayList .class );
128130 if (null == getTenantsResponse ) {
@@ -248,7 +250,7 @@ private byte[] zip(String imagedefinitions) {
248250 ZipOutputStream zip = new ZipOutputStream (stream );
249251 ZipEntry entry = new ZipEntry ("imagedefinitions.json" );
250252 zip .putNextEntry (entry );
251- zip .write (imagedefinitions .getBytes ());
253+ zip .write (imagedefinitions .getBytes (StandardCharsets . UTF_8 ));
252254 zip .closeEntry ();
253255 zip .close ();
254256 archive = stream .toByteArray ();
@@ -266,8 +268,8 @@ private void writeToArtifactBucket(String tenantId, byte[] artifact) {
266268 s3 .putObject (PutObjectRequest .builder ()
267269 .bucket (codePipelineBucket )
268270 .key (key )
269- .build ()
270- , RequestBody .fromBytes (artifact )
271+ .build (),
272+ RequestBody .fromBytes (artifact )
271273 );
272274 } catch (SdkServiceException s3error ) {
273275 LOGGER .error ("s3:PutObject " + Utils .getFullStackTrace (s3error ));
0 commit comments