New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide AWS_PROFILE from configuration for invoke local #5662

Merged
merged 3 commits into from Jan 22, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+71 −1
Diff settings

Always

Just for now

@@ -111,6 +111,12 @@ class AwsInvokeLocal {
NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules', NODE_PATH: '/var/runtime:/var/task:/var/runtime/node_modules',
}; };


// profile override from config
const profileOverride = this.provider.getProfile();
if (profileOverride) {
lambdaDefaultEnvVars.AWS_PROFILE = profileOverride;
}

const providerEnvVars = this.serverless.service.provider.environment || {}; const providerEnvVars = this.serverless.service.provider.environment || {};
const functionEnvVars = this.options.functionObj.environment || {}; const functionEnvVars = this.options.functionObj.environment || {};


@@ -24,6 +24,7 @@ describe('AwsInvokeLocal', () => {
let serverless; let serverless;
let provider; let provider;
let awsInvokeLocal; let awsInvokeLocal;

beforeEach(() => { beforeEach(() => {
options = { options = {
stage: 'dev', stage: 'dev',
@@ -266,12 +267,23 @@ describe('AwsInvokeLocal', () => {
}; };
}); });


afterEach(() => {
delete process.env.AWS_PROFILE;
});

it('it should load provider env vars', () => awsInvokeLocal it('it should load provider env vars', () => awsInvokeLocal
.loadEnvVars().then(() => { .loadEnvVars().then(() => {
expect(process.env.providerVar).to.be.equal('providerValue'); expect(process.env.providerVar).to.be.equal('providerValue');
}) })
); );


it('it should load provider profile env', () => {
serverless.service.provider.profile = 'jdoe';
return awsInvokeLocal.loadEnvVars().then(() => {
expect(process.env.AWS_PROFILE).to.be.equal('jdoe');
});
});

it('it should load function env vars', () => awsInvokeLocal it('it should load function env vars', () => awsInvokeLocal
.loadEnvVars().then(() => { .loadEnvVars().then(() => {
expect(process.env.functionVar).to.be.equal('functionValue'); expect(process.env.functionVar).to.be.equal('functionValue');
@@ -419,6 +419,19 @@ class AwsProvider {
return regionSourceValue.value || defaultRegion; return regionSourceValue.value || defaultRegion;
} }


getProfileSourceValue() {
const values = this.getValues(this, [
['options', 'profile'],
['serverless', 'config', 'profile'],
['serverless', 'service', 'provider', 'profile'],
]);
const firstVal = this.firstValue(values);
return firstVal ? firstVal.value : null;
}
getProfile() {
return this.getProfileSourceValue();
}

getServerlessDeploymentBucketName() { getServerlessDeploymentBucketName() {
if (this.serverless.service.provider.deploymentBucket) { if (this.serverless.service.provider.deploymentBucket) {
return BbPromise.resolve(this.serverless.service.provider.deploymentBucket); return BbPromise.resolve(this.serverless.service.provider.deploymentBucket);
@@ -337,7 +337,6 @@ describe('AwsProvider', () => {
expect(awsProvider.getCredentials()).to.deep.eql({ region: options.region }); expect(awsProvider.getCredentials()).to.deep.eql({ region: options.region });
}); });
}); });

it('should retry if error code is 429', (done) => { it('should retry if error code is 429', (done) => {
const error = { const error = {
statusCode: 429, statusCode: 429,
@@ -991,6 +990,46 @@ describe('AwsProvider', () => {
}); });
}); });


describe('#getProfile()', () => {
let newAwsProvider;

it('should prefer options over config or provider', () => {
const newOptions = {
profile: 'optionsProfile',
};
const config = {
profile: 'configProfile',
};
serverless = new Serverless(config);
serverless.service.provider.profile = 'providerProfile';
newAwsProvider = new AwsProvider(serverless, newOptions);

expect(newAwsProvider.getProfile()).to.equal(newOptions.profile);
});

it('should prefer config over provider in lieu of options', () => {
const newOptions = {};
const config = {
profile: 'configProfile',
};
serverless = new Serverless(config);
serverless.service.provider.profile = 'providerProfile';
newAwsProvider = new AwsProvider(serverless, newOptions);

expect(newAwsProvider.getProfile()).to.equal(config.profile);
});

it('should use provider in lieu of options and config', () => {
const newOptions = {};
const config = {};
serverless = new Serverless(config);
serverless.service.provider.profile = 'providerProfile';
newAwsProvider = new AwsProvider(serverless, newOptions);

expect(newAwsProvider.getProfile()).to.equal(serverless.service.provider.profile);
});
});

describe('#getServerlessDeploymentBucketName()', () => { describe('#getServerlessDeploymentBucketName()', () => {
it('should return the name of the serverless deployment bucket', () => { it('should return the name of the serverless deployment bucket', () => {
const describeStackResourcesStub = sinon const describeStackResourcesStub = sinon
ProTip! Use n and p to navigate between commits in a pull request.