public static async verifyEnvironmentExists()

in src/lib/beanstalkUtils.ts [191:229]


    public static async verifyEnvironmentExists(
        beanstalkClient: ElasticBeanstalk,
        applicationName: string,
        environmentName: string
    ): Promise<void> {
        let envExists = false

        try {
            const response = await beanstalkClient
                .describeEnvironments({
                    ApplicationName: applicationName,
                    EnvironmentNames: [environmentName],
                    IncludeDeleted: false
                })
                .promise()

            if (response.Environments) {
                tl.debug(`Query for environment ${environmentName} yielded ${response.Environments.length} items`)
                envExists = response.Environments.length === 1
                if (response.Environments.length > 1) {
                    console.log(
                        tl.loc(
                            'EnvironmentExistsQueryErrorTooManyEnvironments',
                            applicationName,
                            response.Environments.join(' ,')
                        )
                    )
                }
            } else {
                tl.debug(`Query for environment ${environmentName} yielded an invalid response ${response}`)
            }
        } catch (err) {
            console.log(tl.loc('EnvironmentExistsQueryError', applicationName, environmentName, err))
        }

        if (!envExists) {
            throw new Error(tl.loc('EnvironmentDoesNotExist', environmentName, applicationName))
        }
    }