Skip to content

Commit

Permalink
Updated Preso
Browse files Browse the repository at this point in the history
  • Loading branch information
dchristian3188 committed Aug 4, 2021
1 parent 86f8432 commit 733cee9
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 18 deletions.
5 changes: 3 additions & 2 deletions 02 - Working with EC2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ Get-SSMLatestEC2Image -ImageName 'Windows_Server-2019-English-Full-Base' -Path '
(Get-Command New-EC2Instance).Parameters.Count

# Create Multiple Instances
1..5 | % {
1..5 | ForEach-Object {
Get-SSMLatestEC2Image -ImageName 'Windows_Server-2019-English-Full-Base' -Path 'ami-windows-latest' |
New-EC2Instance -InstanceType t2.large -SecurityGroupId $groupID -KeyName $keyName -UserData $userData -EncodeUserData -Verbose }
New-EC2Instance -InstanceType t2.large -SecurityGroupId $groupID -KeyName $keyName -UserData $userData -EncodeUserData -Verbose
}


# Getting the password
Expand Down
32 changes: 27 additions & 5 deletions 03 - S3.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
# Get Buckets
Get-S3Bucket



# New Bucket
New-S3Bucket -BucketName chradavi-s3-imagebucket-test -Verbose
$bucketName = "chradavi-s3-imagebucket-test"
New-S3Bucket -BucketName $bucketName -Verbose

# Check Encryption
Get-S3Bucket -BucketName $bucketName |
Get-S3BucketEncryption

# Setup Encryption
$Encryptionconfig = @{
ServerSideEncryptionByDefault =
@{ServerSideEncryptionAlgorithm = "AES256"
}}

Set-S3BucketEncryption -BucketName $bucketName -ServerSideEncryptionConfiguration_ServerSideEncryptionRule $Encryptionconfig


Get-S3Bucket -BucketName $bucketName |
Get-S3BucketEncryption


# Delete All Objects in a bucket
Get-S3Object -BucketName chradavi-s3-imagebucket-test |
Get-S3Object -BucketName $bucketName |
Remove-S3Object -Verbose -Force

# Upload Objects to a bucket
Get-Item -Path .\Pics\* |
Get-Item -Path C:\github\PowerShellAndAWS\Pics\* |
ForEach-Object {
$key = [io.path]::Combine("input",$PSItem.Name)
Write-S3Object -BucketName chradavi-s3-imagebucket-test -File $PSItem.FullName -Verbose -Key $key
Write-S3Object -BucketName $bucketName -File $PSItem.FullName -Verbose -Key $key
}


# Delete a bucket
Get-S3Bucket $bucketName |
Remove-S3Bucket -Verbose -Force
7 changes: 4 additions & 3 deletions 04 - CloudWatch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Get-CWLLogGroup -LogGroupNamePrefix '/aws/lambda/ResizeS3Photos' |

# Find the log streams
Get-CWLLogGroup -LogGroupNamePrefix '/aws/lambda/ResizeS3Photos' |
Get-CWLLogStream
Get-CWLLogStream |
Sort-Object -Descending CreationTime

# Looking at the events
Get-CWLLogEvent -LogGroupName '/aws/lambda/ResizeS3Photos' -LogStreamName '2021/08/02/[$LATEST]effe97aece154f6a866db8d2b0621e92'
Get-CWLLogEvent -LogGroupName '/aws/lambda/ResizeS3Photos' -LogStreamName '2021/08/03/[$LATEST]348c1e96f50748299ffc361ca8ffbeb4'

Get-CWLLogEvent -LogGroupName '/aws/lambda/ResizeS3Photos' -LogStreamName '2021/08/02/[$LATEST]effe97aece154f6a866db8d2b0621e92' |
Get-CWLLogEvent -LogGroupName '/aws/lambda/ResizeS3Photos' -LogStreamName '2021/08/03/[$LATEST]348c1e96f50748299ffc361ca8ffbeb4' |
Select-Object -ExpandProperty Events

# A better log function
Expand Down
6 changes: 3 additions & 3 deletions 05 - Lambda.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Get-AWSPowerShellLambdaTemplate
# Creating A Lambda
New-AWSPowerShellLambda -Template basic -Directory 'C:\github\PowerShellAndAWS\BasicLambda'

Publish-AWSPowerShellLambda -ScriptPath 'C:\github\PowerShellAndAWS\BasicLambda\basic.ps1' -Name 'BasicLambda' -Verbose
# Publish Our Lambda
Publish-AWSPowerShellLambda -ScriptPath 'C:\github\PowerShellAndAWS\BasicLambda\basic.ps1' -Name 'BasicLambda' -Verbose

# Testing out the lambda
Invoke-LMFunction -FunctionName 'BasicLambda' -LogType Tail -OutVariable BasicLmabda

[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($BasicLmabda.LogResult))



# More Advanced
New-AWSPowerShellLambda -Template S3Event -ProjectName ResizeS3Photos -WithProject -Verbose

Expand Down
31 changes: 31 additions & 0 deletions 06 - CICD.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# CDK Intro

# Cloning a new Repo

git clone https://git-codecommit.us-west-2.amazonaws.com/v1/repos/PowerShell-Repository

# Generating the lambda package

Set-Location -Path C:\github\PowerShell-Repository

New-AWSPowerShellLambda -Template basic -Verbose
Copy-Item -Path C:\github\PowerShellAndAws\LambdaTemplateExample\buildspec.yaml -Destination . -Verbose
Code C:\github\PowerShell-Repository

# Check In Our Code, Review the pipeline


# Invoke Our Function
Invoke-LMFunction -FunctionName 'PowerShellCICD-Sample' -LogType Tail
Get-CWLLastLogEvent -LogGroupNamePrefix '/aws/lambda/PowerShellCICD-Sample'


## Make a change and watch the build

While($true)
{
Start-Sleep -Seconds 5
Invoke-LMFunction -FunctionName 'PowerShellCICD-Sample' -LogType Tail -Verbose
Get-CWLLastLogEvent -LogGroupNamePrefix '/aws/lambda/PowerShellCICD-Sample'
}

3 changes: 2 additions & 1 deletion BasicLambda/basic.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
#Requires -Modules @{ModuleName='AWS.Tools.Common';ModuleVersion='4.1.14.0'}

# Uncomment to send the input event to CloudWatch Logs
# Write-Host (ConvertTo-Json -InputObject $LambdaInput -Compress -Depth 5)
Write-Host (ConvertTo-Json -InputObject $LambdaInput -Compress -Depth 5)
Write-Host "Hello SoCalPosh"
9 changes: 5 additions & 4 deletions HelperFunctions/Get-CWLLastLogEvent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Function Get-CWLLastLogEvent
$LogGroupNamePrefix
)

$logStreams = Get-CWLLogGroup -LogGroupNamePrefix $LogGroupNamePrefix |
$logStream = Get-CWLLogGroup -LogGroupNamePrefix $LogGroupNamePrefix |
Get-CWLLogStream |
Sort-Object -desc -Property CreationTime |
Select-Object -First 1

Get-CWLLogEvent -LogGroupName $LogGroupNamePrefix -LogStreamName $logStreams.LogStreamName |
Select-Object -ExpandProperty Events
}
$events = Get-CWLLogEvent -LogGroupName $LogGroupNamePrefix -LogStreamName $logStream.LogStreamName
$events.Events
}

16 changes: 16 additions & 0 deletions LambdaTemplateExample/basic/basic.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# PowerShell script file to be executed as a AWS Lambda function.
#
# When executing in Lambda the following variables will be predefined.
# $LambdaInput - A PSObject that contains the Lambda function input data.
# $LambdaContext - An Amazon.Lambda.Core.ILambdaContext object that contains information about the currently running Lambda environment.
#
# The last item in the PowerShell pipeline will be returned as the result of the Lambda function.
#
# To include PowerShell modules with your Lambda function, like the AWS.Tools.S3 module, add a "#Requires" statement
# indicating the module and version. If using an AWS.Tools.* module the AWS.Tools.Common module is also required.

#Requires -Modules @{ModuleName='AWS.Tools.Common';ModuleVersion='4.1.14.0'}

# Uncomment to send the input event to CloudWatch Logs
Write-Host (ConvertTo-Json -InputObject $LambdaInput -Compress -Depth 5)
Write-Host "Hello World"
15 changes: 15 additions & 0 deletions LambdaTemplateExample/basic/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# PowerShell script file to be executed as a AWS Lambda function.
#
# When executing in Lambda the following variables will be predefined.
# $LambdaInput - A PSObject that contains the Lambda function input data.
# $LambdaContext - An Amazon.Lambda.Core.ILambdaContext object that contains information about the currently running Lambda environment.
#
# The last item in the PowerShell pipeline will be returned as the result of the Lambda function.
#
# To include PowerShell modules with your Lambda function, like the AWS.Tools.S3 module, add a "#Requires" statement
# indicating the module and version. If using an AWS.Tools.* module the AWS.Tools.Common module is also required.

#Requires -Modules @{ModuleName='AWS.Tools.Common';ModuleVersion='4.1.14.0'}

# Uncomment to send the input event to CloudWatch Logs
# Write-Host (ConvertTo-Json -InputObject $LambdaInput -Compress -Depth 5)
9 changes: 9 additions & 0 deletions LambdaTemplateExample/buildspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 0.2

phases:
install:
commands:
- pwsh -command Install-Module -Name AWSLambdaPSCore -Verbose -Force
build:
commands:
- pwsh -command Publish-AWSPowerShellLambda -ScriptPath ./basic/basic.ps1 -Name 'PowerShellCICD-Sample' -IAMRoleArn arn:aws:iam::124535484568:role/PowerShell-Lambda-ExecutionRole -Verbose

0 comments on commit 733cee9

Please sign in to comment.