Skip to content

Commit

Permalink
Add EnvVar Step
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPates committed Jan 23, 2023
1 parent ba5efeb commit 4425e6d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
21 changes: 21 additions & 0 deletions cicd/EnvVarConfig/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 0.2

phases:
install:
commands:
# Update sam to latest version
- wget -q https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
- unzip -q awscli-exe-linux-x86_64.zip
- sudo ./aws/install --update
- rm -rf ./aws awscli-exe-linux-x86_64.zip

pre_build:
commands:
# Print all environment variables (handy for AWS CodeBuild logs)
- env

build:
commands:
# Set the Environment Variable to enable CodePipeline
aws lambda update-function-configuration --function-name SSOSyncFunction --environment "Variables={RUNNING_IN_CODEPIPELINE=True}" --query "Environment"

49 changes: 47 additions & 2 deletions cicd/cloudformation/dev-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,27 @@ Resources:
- Name: E2ELambda
InputArtifacts:
- Name: Source
- Name: EnvVarConfig
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
RunOrder: 2
Configuration:
ProjectName: !Ref CodeBuildEnvVarConfig
PrimarySource: Source
OutputArtifacts:
- Name: EnvVarConfig
InputArtifacts:
- Name: Source
- Name: TestCodePipeline
ActionTypeId:
Category: Invoke
Owner: AWS
Version: 1
Provider: Lambda
RunOrder: 2
RunOrder: 3
Configuration:
FunctionName: SSOSyncFunction
OutputArtifacts:
Expand Down Expand Up @@ -506,6 +520,37 @@ Resources:
LogGroupName: !Ref CodePipelineLogGroup
LogStreamName: !Sub "${ApplicationName}-Deploy"

CodeBuildEnvVarConfig:
Type: AWS::CodeBuild::Project
Properties:
Name: !Sub "${ApplicationName}-Set-EnvVar"
Description: !Sub Use the GitHub metadata to determine whether this commit is a release
ServiceRole: !Ref CodeBuildTestRole
Source:
Type: CODEPIPELINE
BuildSpec: "cicd/EnvVarConfig/buildspec.yml"
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:5.0
Type: LINUX_CONTAINER
EnvironmentVariables:
- Name: FunctionName
Value: SSOSyncFunction
Artifacts:
Name: !Ref ApplicationName
Type: CODEPIPELINE
LogsConfig:
CloudWatchLogs:
GroupName: !Ref CodePipelineLogGroup
StreamName: !Ref CodeBuildEnvVarConfigLogs
Status: ENABLED

CodeBuildEnvVarConfigLogs:
Type: AWS::Logs::LogStream
Properties:
LogGroupName: !Ref CodePipelineLogGroup
LogStreamName: !Sub "${ApplicationName}-EnvVarConfig"

CodeBuildE2ETest:
Type: AWS::CodeBuild::Project
Properties:
Expand Down Expand Up @@ -541,7 +586,6 @@ Resources:
LogGroupName: !Ref CodePipelineLogGroup
LogStreamName: !Sub "${ApplicationName}-E2ETest"


CodePipelineRole:
Type: AWS::IAM::Role
Properties:
Expand Down Expand Up @@ -603,6 +647,7 @@ Resources:
- 'lambda:InvokeFunction'
Resource:
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:SSOSyncFunction
Effect: Allow

CodeBuildAppRole:
Type: AWS::IAM::Role
Expand Down

0 comments on commit 4425e6d

Please sign in to comment.