Skip to content

Commit

Permalink
allow to use credentials from env
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Dec 15, 2021
1 parent d6d7665 commit 10ae3cb
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,41 @@ async function run() {
if (!AWS_REGION) {
throw "No AWS_REGION provided!";
}
if (!AWS_SECRET_KEY) {
throw "No AWS_SECRET_KEY provided!";
}
if (!AWS_SECRET_ID) {
throw "No AWS_SECRET_ID provided!";
}

console.log(`Deploying ${FUNCTION_NAME} from ${ZIP}.`);
core.debug(`Deploying ${FUNCTION_NAME} from ${ZIP}.`);

const zipBuffer = fs.readFileSync(`./${ZIP}`);
core.debug("ZIP read into memory.");

const lambda = new AWS.Lambda({
apiVersion: "2015-03-31",
region: AWS_REGION,
secretAccessKey: AWS_SECRET_KEY,
accessKeyId: AWS_SECRET_ID,
maxRetries: 3,
sslEnabled: true,
logger: console,
});

if (AWS_SECRET_ID) {
core.debug(`Using AWS_SECRET_ID`);
lambda.config.update({
accessKeyId: AWS_SECRET_ID,
});
}

if (AWS_SECRET_KEY) {
core.debug(`Using AWS_SECRET_KEY`);
lambda.config.update({
secretAccessKey: AWS_SECRET_KEY,
});
}

const uploadParams = {
FunctionName: FUNCTION_NAME,
Publish: true,
ZipFile: zipBuffer,
};

core.debug(`Updating function code...`);
await lambda.updateFunctionCode(uploadParams).promise();

let configParams = {
Expand Down Expand Up @@ -84,6 +91,7 @@ async function run() {
}

if (Object.keys(configParams).length > 1) {
core.debug(`Updating function configuration...`);
await lambda
.waitFor("functionUpdated", {
FunctionName: FUNCTION_NAME,
Expand Down

0 comments on commit 10ae3cb

Please sign in to comment.