CloudFormationでSSMしたい
AWSTemplateFormatVersion: 2010-09-09
Parameters:
# EnvironmentName:
# Type: String
# Default: test-environment
SelectRegion:
Type: String
Default: TokyoRegion
AllowedValues:
- TokyoRegion
- OsakaRegion
KeyPair:
Type: AWS::EC2::KeyPair::KeyName
Default: ""
LinuxLatestAmi:
Type: AWS::SSM::Parameter::Value<String>
Default: "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
InstanceType:
Type: String
AllowedValues: ["t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "t2.xlarge", "t2.2xlarge"]
Default: "t2.micro"
Mappings:
TokyoRegion:
VPC:
VPCCidrBlock: 10.0.0.0/16
Subnet:
PrivateSubnet: 10.0.1.0/16
OsakaRegion:
VPC:
VPCCidrBlock: 192.168.0.0/16
Subnet:
PrivateSubnet: 192.168.1.0/16
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !FindInMap [ !Ref SelectRegion, VPC, VPCCidrBlock ]
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-VPC"
Subnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: !FindInMap [ !Ref SelectRegion, Subnet, PrivateSubnet ]
#GIPは取得しない
MapPublicIpOnLaunch: 'False'
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-Subnet"
EC2Linux:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref LinuxLatestAmi
InstanceType: !Ref InstanceType
IamInstanceProfile: !Ref InstanceProfile
KeyName: !Ref KeyPair
SubnetId: !Ref Subnet
SecurityGroupIds:
- !GetAtt EC2LinuxSecurityGroup.GroupId
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-EC2Linux"
EC2LinuxSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SGlinux
VpcId: !Ref VPC
#インバウンドルールは設定しない。アウトバウンドルールは全て許可する。
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-EC2LinuxSecurityGroup"
EC2Role:
Type: AWS::IAM::Role
Properties:
Path: /
RoleName: !Sub ${AWS::StackName}-EC2Role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
MaxSessionDuration: 3600
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref EC2Role
# --------------------------------------------------------------------------------------------
# for SSM setting Zone
# --------------------------------------------------------------------------------------------
SSMSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SGlinux
VpcId: !Ref VPC
#SSM用のセキュリティグループ
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-SSMSecurityGroup"
# ------------------------------------------------------------#
# Create ssm End Point
# ------------------------------------------------------------#
ssmEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub "com.amazonaws.${AWS::Region}.ssm"
SubnetIds:
- !Ref Subnet
VpcId: !Ref VPC
VpcEndpointType: Interface
SecurityGroupIds:
- !Ref SSMSecurityGroup
PrivateDnsEnabled: true
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-ssmEndpoint"
# ------------------------------------------------------------#
# Create EC2Message End Point
# ------------------------------------------------------------#
EC2MessageEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub "com.amazonaws.${AWS::Region}.ec2messages"
SubnetIds:
- !Ref Subnet
VpcId: !Ref VPC
VpcEndpointType: Interface
SecurityGroupIds:
- !Ref SSMSecurityGroup
PrivateDnsEnabled: true
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-EC2MessageEndpoint"
# ------------------------------------------------------------#
# Create ssmmessages End Point
# ------------------------------------------------------------#
ssmmessagesEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub "com.amazonaws.${AWS::Region}.ssmmessages"
SubnetIds:
- !Ref Subnet
VpcId: !Ref VPC
VpcEndpointType: Interface
SecurityGroupIds:
- !Ref SSMSecurityGroup
PrivateDnsEnabled: true
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-${SelectRegion}-ssmmessagesEndpoint"
エクセルでdiff
Sub diff() Dim r As Range On Error Resume Next Set r = Application.InputBox(prompt:="編集後のセル範囲指定をしてください", Type:=8) r.Select Application.CutCopyMode = False Dim rng As Range Set rng = Application.InputBox(prompt:="編集前シートの左上のセルを選択してください。", Type:=8) Debug.Print rng.Parent.Name Debug.Print rng.Address(False, False) Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, Formula1:="=" & rng.Parent.Name & "!" & rng.Address(False, False) Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 5296274 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = False Range("A1").Select End Sub
会員番号 氏名 電話番号
0001 田中一応 09012341111
0002 佐藤敬一郎 05044449999
0003 牧三郎 08033334567
0004 鈴木圭太 01029998887
0005 山本山自動 02089888897
0006 平井大和 05067894321
0007 翔みなと 03077788888
0008 今井平井 06078900987
0009 前田花子 03066661111
↑みたいなデータを
会員番号 氏名 電話番号
0001 田中一応 09012341111
0002 佐藤敬一郎 05044449999
0003 巻三郎 08033334567
0004 鈴木圭太 01029998888
0005 山本川次郎 02089888897
0006 平井大和 05067894321
0007 翔みなと 03077788888
0008 今井平井 06078900987
0009 前田花子 03066661111
のように編集した場合に差分を見つけることができるようになります。
Visual Studio Code の拡張機能の更新でハマったのでメモ
タイトルの通りですが、Visual Studio Code の拡張機能の更新でハマったのでメモします。
以下にログインする。
https://marketplace.visualstudio.com/manage/publishers/
以下の画像の通りPersonal access tokensをクリック
Personal Access Tokensの『+ New Token』をクリック
OrganizationはAll accessible organizationsを設定する
ScopesはFull Accessを設定する
Nameは統一しておいた方がいいかも。
赤枠のtokenは重要なので保存しておく
コマンドプロンプトを起動し、以下のコマンドを実行する
%USERPROFILE%\>vsce login [username]
https://marketplace.visualstudio.com/manage/publishers/
Personal Access Token for publisher [username]:****************************************************
[username]はCreate a new personal access tokenで決めた名前
****************************************************は上で保存したtokenを貼り付ける
extentionファイルのあるディレクトリにcdし、以下のコマンドを実行
vsce publish patch
その際、フォルダのバージョンと現在のバージョンを合わせておくこと。
patchにすると、細かい変更点を考慮せずに更新できます。
ファイルのpackage.jsonのバージョンの欄を書き換えて
vsce publish
でもOKですがpatchの方が簡単ですのでお勧めです。
VBAでフォルダを指定してエクセルファイル内の文字列を検索
Option Explicit Dim myWB As Workbook Dim varArray As Variant Dim myStr As Variant Dim targetFolder As String Dim fso As Object Sub フォルダ指定文字列検索() Application.ScreenUpdating = False Application.EnableEvents = False Call 文字入力 varArray = Array(myStr) 'フォルダの指定 Dim strDirPath As String 'フォルダの選択 With Application.FileDialog(msoFileDialogFolderPicker) If .Show = True Then targetFolder = .SelectedItems(1) End With If Len(targetFolder) = 0 Then End Call Add_myBook Set fso = CreateObject("Scripting.fileSystemObject") '対象フォルダ配下(サブフォルダ)の全ファイルに対する処理(再起処理) Call loopAllFiles(targetFolder, fso) Set fso = Nothing 'イベント抑止を解除 Application.EnableEvents = True '画面更新の停止 Application.ScreenUpdating = True myWB.Worksheets(1).Columns("A:C").AutoFit MsgBox prompt:="処理が終了しました。" End Sub '対象フォルダ配下(サブフォルダ)の全ファイルに対する処理(再起処理) Private Function loopAllFiles(targetFolder As String, fso As Object) Const FILE_TYPE_XLSX As String = "xlsx" Const FILE_TYPE_XLS As String = "xls" Dim folder As Object Dim file As Object 'サブフォルダの数だけ再帰 For Each folder In fso.GetFolder(targetFolder).SubFolders Call loopAllFiles(folder.Path, fso)
'ここでdebugしておくとイミディエイトウィンドウで幸せになれる
debug.print folder.path Next folder 'ファイルの数分繰り返し For Each file In fso.GetFolder(targetFolder).Files Dim extentionName As String extentionName = fso.GetExtensionName(file.Name) If LCase(extentionName) = FILE_TYPE_XLSX Or LCase(extentionName) = FILE_TYPE_XLS Then 'Excelファイルに対する処理 Call execExcelFile(file) End If Next file End Function 'Excelファイルに対する処理 Private Function execExcelFile(file As Object) Dim wkbook As Workbook On Error Resume Next Set wkbook = Workbooks.Open(Filename:=file.Path, UpdateLinks:=0, corruptload:=xlRepairFile, Password:="", IgnoreReadOnlyRecommended:=True, ReadOnly:=True) Debug.Print wkbook.Name Call Books_Find_Main(wkbook) End Function
Private Sub Add_myBook()
Set myWB = Workbooks.Add
With myWB.Worksheets(1)
.Cells(1, 1).Value = "検索文字列:" & Join$(varArray, ",")
.Cells(2, 1) = targetFolder
.Cells(3, 1).Resize(, 4).Value = Array("フォルダパス", "ブック名", "シート名", "セルアドレス")
End With
End Sub
Private Sub Books_Find_Main(WB As Workbook) 'ブック内全シートの検索 Dim v As Variant, strAddress As String Dim Sh As Worksheet, rngFnd As Range, rngUni As Range With WB .Activate For Each Sh In .Worksheets For Each v In varArray Set rngFnd = Sh.Cells.Find(What:=v, LookAt:=xlPart) '検索 If Not rngFnd Is Nothing Then strAddress = rngFnd.Address '最初に検索一致したセルのアドレス格納 If rngUni Is Nothing Then Set rngUni = rngFnd Do Set rngUni = Union(rngUni, rngFnd) 'セルを集合 Set rngFnd = Sh.Cells.FindNext(rngFnd) Loop Until strAddress = rngFnd.Address End If Next If Not rngUni Is Nothing Then With myWB.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1) '.Value = WB.FullName
.Hyperlinks.Add Anchor:=.Offset(0), Address:=WB.Path, TextToDisplay:=WB.Path
.Hyperlinks.Add Anchor:=.Offset(, 1), Address:=WB.FullName, TextToDisplay:=WB.Name
.Offset(, 2).Value = Sh.Name
.Offset(, 3).Value = rngUni.Address(False, False)
End With Set rngUni = Nothing End If Next .Close SaveChanges:=False End With End Sub Sub 文字入力() inputKensaku: On Error GoTo ErrHandle myStr = InputBox(prompt:="検索する文字を入力してください", Title:="検索文字列入力") If Len(myStr) = 0 Then End End If Exit Sub ErrHandle: MsgBox Err.Description & String(2, vbCrLf) & "再度入力してください", vbCritical Resume inputKensaku End Sub
FindNextの使い方
Sub macro3()
Dim myRange As Range
Dim myObj As Range
Dim keyWord As String
Set myRange = Range("A1:A12")
keyWord = Range("C3")
Set myObj = myRange.Find(keyWord, LookAt:=xlWhole)
If myObj Is Nothing Then
MsgBox "'" & keyWord & "'はありませんでした"
Exit Sub
End If
Dim msg As String
Dim myCell As Range
Set myCell = myObj
Do
msg = msg & "'" & keyWord & "'は" & myCell.Row & "行目にあります" & vbCrLf
Set myCell = myRange.FindNext(myCell)
Loop While myCell.Row <> myObj.Row
MsgBox msg
End Sub
リストから別シートの別の列の値を検索して抽出したい
Sub 一致検索()
Dim i As Long '店舗一覧の行数のカウントアップ用
Dim j As Long '転記先の行数のカウントアップ用
Dim k As Long
Dim rw As Long '最終行取得用
Sheets("店舗一覧").Activate
rw = Cells(Rows.Count, 1).End(xlUp).Row
Sheets("店舗ID").Activate
rx = Cells(Rows.Count, 1).End(xlUp).Row
j = 4 '初期設定
k = 4
l = 2
For l = 2 To rx
Worksheets("店舗ID").Range("A" & l).Copy Destination:=Range("E" & k)
For i = 2 To rw
If Sheets("店舗一覧").Cells(i, 1) = Worksheets("店舗ID").Range("E" & k) Then
With Sheets("店舗ID")
.Cells(j, 6) = Sheets("店舗一覧").Cells(i, 3)
j = j + 1
End With
End If
Next i
k = j
Debug.Print k
Next l
End Sub
店舗一覧シート
店舗ID