Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# codepipeline-s3-objects-public-read

A CASE (copy and steal everything!!! ;-) ) study from [Sam Dengler's original](https://github.com/samdengler/codepipeline-s3-objects-public-read) . Added the environment variable 'BUILD_ARTIFACT'.

[AWS CodePipeline](https://aws.amazon.com/codepipeline/) is a fully managed continuous delivery (CD) service that lets you automate your software release process for fast and reliable updates. You can now use CodePipeline to deploy files, such as static website content or artifacts from your build process, to Amazon S3.

The S3 deployment action makes it very easy to update S3 Buckets used to host static websites, however the objects deployed do not have Public Read Access. In cases where the S3 Bucket policy does no allow Public Read Access, this prevents users from accessing the website content.
Expand Down
5 changes: 3 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const codepipeline = new AWS.CodePipeline();

const process = require('process');
const S3_BUCKET = process.env.S3_BUCKET;
const BUILD_ARTIFACT = process.env.BUILD_ARTIFACT
const PUBLIC_READ_ACL = "public-read";

exports.handler = async (event, context) => {
Expand Down Expand Up @@ -36,7 +37,7 @@ exports.handler = async (event, context) => {
}

async function listObjectsFromBuildArtifact(jobData) {
let buildArtifact = jobData.inputArtifacts.filter(i => i.name === "BuildArtifact")[0];
let buildArtifact = jobData.inputArtifacts.filter(i => i.name === BUILD_ARTIFACT)[0];
let artifactS3Client = new AWS.S3({
accessKeyId: jobData.artifactCredentials.accessKeyId,
secretAccessKey: jobData.artifactCredentials.secretAccessKey,
Expand Down Expand Up @@ -81,4 +82,4 @@ async function putJobFailureResult(jobId, message) {
};

return codepipeline.putJobFailureResult(params).promise();
}
}
13 changes: 9 additions & 4 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ Transform: AWS::Serverless-2016-10-31
Parameters:
S3BucketParameter:
Type: String
BuildArtifactParameter:
Type: String
Default: BuildArtifact

Metadata:
AWS::ServerlessRepo::Application:
Name: codepipeline-s3-objects-public-read
Description: A Lambda function triggered by CodePipeline to update the S3 ACL to Public Read for objects deployed via S3 Deploy action.
Author: Sam Dengler
Description: A Lambda function triggered by CodePipeline to update the S3 ACL to Public Read for objects deployed via S3 Deploy action. Originally from Sam Dengler.
Author: George Seib
SpdxLicenseId: Apache-2.0
LicenseUrl: LICENSE.txt
ReadmeUrl: README.md
Labels: ['codepipeline','s3']
HomePageUrl: https://github.com/samdengler/codepipeline-s3-objects-public-read
HomePageUrl: https://github.com/geseib/codepipeline-s3-objects-public-read
SemanticVersion: 0.0.1
SourceCodeUrl: https://github.com/samdengler/codepipeline-s3-objects-public-read
SourceCodeUrl: https://github.com/geseib/codepipeline-s3-objects-public-read

Resources:
PublicReadAclFunction:
Expand All @@ -29,6 +32,8 @@ Resources:
Environment:
Variables:
S3_BUCKET: !Ref S3BucketParameter
BUILD_ARTIFACT: !Ref BuildArtifactParameter

Policies:
- S3FullAccessPolicy:
BucketName: !Ref S3BucketParameter
Expand Down