io.ignitr.dispatchr.manager.Application.java Source code

Java tutorial

Introduction

Here is the source code for io.ignitr.dispatchr.manager.Application.java

Source

/*
 * Copyright 2016 Greg Whitaker
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.ignitr.dispatchr.manager;

import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.sns.AmazonSNSClient;
import io.ignitr.springboot.common.metadata.DeploymentContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * Starts the Dispatchr Manager.
 */
@SpringBootApplication(scanBasePackages = { "io.ignitr" })
public class Application {

    /**
     * Main entry-point of the application.
     *
     * @param args command line arguments
     */
    public static void main(String... args) {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    @Bean
    public AmazonSNSClient amazonSNSClient(DeploymentContext deploymentContext) {
        AmazonSNSClient client = new AmazonSNSClient(new DefaultAWSCredentialsProviderChain());
        client.setRegion(Region.getRegion(Regions.fromName(deploymentContext.getRegion())));

        return client;
    }

    @Autowired
    @Bean
    public AmazonDynamoDBClient amazonDynamoDBClient(DeploymentContext deploymentContext) {
        AmazonDynamoDBClient client = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain());
        client.setRegion(Region.getRegion(Regions.fromName(deploymentContext.getRegion())));

        return client;
    }

    @Autowired
    @Bean
    public DynamoDB dynamoDB(AmazonDynamoDBClient amazonDynamoDBClient) {
        return new DynamoDB(amazonDynamoDBClient);
    }
}