diff --git a/packages/amplify-e2e-tests/src/__tests__/tags.test.ts b/packages/amplify-e2e-tests/src/__tests__/tags.test.ts index e74e2535971..300f6a79c22 100644 --- a/packages/amplify-e2e-tests/src/__tests__/tags.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/tags.test.ts @@ -3,12 +3,12 @@ import { createNewProjectDir, deleteProject, deleteProjectDir, - amplifyPushWithoutCodegen, getProjectMeta, getProjectTags, describeCloudFormationStack, - addDEVHosting, } from 'amplify-e2e-core'; +import _ from 'lodash'; +import { Amplify } from 'aws-sdk'; describe('generated tags test', () => { let projRoot: string; @@ -23,11 +23,7 @@ describe('generated tags test', () => { }); it('should compare the nested stack tags key with the tags.json file and return true', async () => { - const projName = 'tagsTest'; - const envName = 'devtag'; - await initJSProjectWithProfile(projRoot, { name: projName, envName }); - await addDEVHosting(projRoot); - await amplifyPushWithoutCodegen(projRoot); + await initJSProjectWithProfile(projRoot, { disableAmplifyAppCreation: false }); // This block of code gets the necessary info to compare the values of both the local tags from the JSON file and tags on the stack const amplifyMeta = getProjectMeta(projRoot); @@ -35,10 +31,18 @@ describe('generated tags test', () => { const rootStackInfo = await describeCloudFormationStack(meta.StackName, meta.Region); const localTags = getProjectTags(projRoot); - // Currently only checks to make sure that thhe pushed tags have the same amount and name of keys than the ones added locally on the tags.json file - expect(checkEquality(localTags, rootStackInfo.Tags)).toBe(true); - expect(rootStackInfo.Tags.filter(r => r.Key === 'user:Stack')[0].Value).toEqual(envName); - expect(rootStackInfo.Tags.filter(r => r.Key === 'user:Application')[0].Value).toEqual(projName); + expect(checkEquality(localTags, rootStackInfo.Tags)).toBeTruthy(); + const { AmplifyAppId, Region } = meta; + const amplify = new Amplify({ region: Region }); + const amplifyApp = await amplify.getApp({ appId: AmplifyAppId }).promise(); + const tagMap = amplifyApp.app.tags; + const amplifyTags = Object.keys(tagMap).map(key => { + return { + Key: key, + Value: tagMap[key], + }; + }); + expect(checkEquality(localTags, amplifyTags)).toBeTruthy(); }); }); diff --git a/packages/amplify-provider-awscloudformation/src/amplify-service-manager.js b/packages/amplify-provider-awscloudformation/src/amplify-service-manager.js index 92ca82e5d95..84a27a7c373 100644 --- a/packages/amplify-provider-awscloudformation/src/amplify-service-manager.js +++ b/packages/amplify-provider-awscloudformation/src/amplify-service-manager.js @@ -18,6 +18,7 @@ async function init(amplifyServiceParams) { let deploymentBucketName = `${stackName}-deployment`; const amplifyClient = await getConfiguredAmplifyClient(context, awsConfig); + logger('init.getConfiguredAmplifyClient', [!!amplifyClient])(); if (!amplifyClient) { // This happens when the Amplify service is not available in the region return { @@ -28,6 +29,7 @@ async function init(amplifyServiceParams) { } const hasPermission = await checkAmplifyServiceIAMPermission(context, amplifyClient); + logger('init.checkAmplifyServiceIAMPermission', [hasPermission])(); if (!hasPermission) { return { amplifyAppId, @@ -115,13 +117,18 @@ async function init(amplifyServiceParams) { } if (!amplifyAppId) { + logger('in if', [amplifyAppId])(); + const createAppParams = { name: projectName, + tags: getTagMap(context), environmentVariables: { _LIVE_PACKAGE_UPDATES: '[{"pkg":"@aws-amplify/cli","type":"npm","version":"latest"}]' }, }; + logger('after create params', [amplifyAppId])(); const log = logger('init.amplifyClient.createApp', [createAppParams]); try { + logger('amplifyAppCreationEnabled', [amplifyAppCreationEnabled()])(); if (amplifyAppCreationEnabled()) { log(); const createAppResponse = await amplifyClient.createApp(createAppParams).promise(); @@ -202,6 +209,14 @@ async function init(amplifyServiceParams) { deploymentBucketName, }; } +function getTagMap(context) { + const tags = context.amplify.getTags(context); + const tagMap = tags.reduce((obj, tag) => { + obj[tag.Key] = tag.Value; + return obj; + }, {}); + return tagMap; +} async function deleteEnv(context, envName, awsConfig) { if (stateManager.teamProviderInfoExists()) { @@ -291,6 +306,7 @@ async function postPushCheck(context) { if (!amplifyAppId) { const createAppParams = { name: projectConfig.projectName, + tags: getTagMap(context), environmentVariables: { _LIVE_PACKAGE_UPDATES: '[{"pkg":"@aws-amplify/cli","type":"npm","version":"latest"}]' }, }; const log = logger('postPushCheck.amplifyClient.createApp', [createAppParams]);