Overview# In the following article, I described how to perform health checks.
I also described the command for restarting Virtuoso when it stops in the following article.
This time, I will try restarting Virtuoso in conjunction with Amazon SNS notifications.
Method# To send a command like sudo rm -rf /usr/local/var/lib/virtuoso/db/virtuoso.lck && ... to an EC2 instance, SSM (AWS Systems Manager) configuration was required.
IAM Roles and Policies# I created a new IAM role and granted the AmazonSSMFullAccess policy. Initially, I had granted the AmazonSSMManagedInstanceCore policy, but the following error occurred when executing the Lambda function described later, and it did not work properly.
A n e r r o r o c c u r r e d ( I n v a l i d I n s t a n c e I d ) w h e n c a l l i n g t h e S e n d C o m m a n d o p e r a t i o n : I n s t a n c e s [ [ i - x x x x x x ] ] n o t i n a v a l i d s t a t e f o r a c c o u n t x x x x x x
I selected and updated the created IAM role from “Modify IAM role” on the EC2 instance.
AWS SAM: Creating the Lambda Function# I used AWS SAM. Create a project with the following:
s a m i n i t
I created hello_world/app.py as follows. The instance_id part needs to be modified.
i i d m m e p p f o o r r l # e # i # r i # c # s r t c o p # s } r t t a c n e f o s e i o u r i e m I 2 S s C s D m S m s m m t i E m t b t b n p t h p l e m e _ p e m p n x p u o i d i = e a e o e p r f a n c o I D P . a u C I t t l " " r t m a t c n c n n r e i n d l n n o a s n t o n ( r i O E n o e _ i b i c k s ( i t n d i s s c r l d m s " a f u r 3 h a o f e e r n u e c e e t u a e _ = m t コ c i t r s a l t y _ E e t r = o n a m m e i a a マ t e p o i n i o i C = s ( n t m t = n e e p d s n n ン d u r m d z 3 a d 2 p f h ' m c n t ( s d c ド o _ t " p l e . e o " e s a = s e t e 1 = m I e を n r " : l e c s = i c n イ u n s I N r . _ d I 実 l e : i r E l p n 2 s ン c d d b m d a s 0 r c = d 行 y s o f ( C i e ' s . e ス o o o _ s m = ) e l c = し p o u i e 2 e c i t d [ タ m t t c = e { s i o i ま t o u t e v n i - a e ' ン m r o o l [ = ' p e m n し h n t p d e c t f x n s I ス a m 3 i i ' c o n m s た e s p u _ n l ( i x c c n n E . e n A o n t a t 。 e u t r t i ' c x e r s { d - C c n s W m s . n a " n t [ e , e e x i t i r 2 l t t S m e g d n ) e = [ ' s n c E x s b a n t f i . a - a [ e _ c c ' S p c t 2 C x t e n s o i e s n R n ' t i e e { S t o o ' 2 x a _ c t / n n e c u d C _ d _ s t a n n ) x t i e a b u s t n e n s o c , i s a n s t i ' u n S n e s t ( d _ S ' m o d a n d e e n s s t c r a ' _ i h : m m , r d a x s t a e e / n s c d e a m y a r t t a t _ x l c s o ] l [ n a r d ) a n u i e o e m m , l c d n i d E : n c s d c c ' m S o ' d n O r c e e } u a v ) a c m ] _ f u r e _ s t l i n r m [ i o t o s ' は e / a d i a ' n r p r I t ] 停 d v ( p n C v m u C D a ) 止 a S t d o o a t o t 中 o r S ' ] m c t C n u = で n / M , } m a i o t s = す l a t o n e ( 。 t i n i n t n I 0 " h b d o e t n : ) e / I n f n ' s v d ( r t ] t i i ' o ' , a n r ] m ] n s t , c t u t e a o h I n s e d c o s e / o = d u [ ( b t i e p n . v u s g i t t . r a , t n u c r o e e s _ s o i t . d a l ] r c ) t k s & o & f t s w u a d r o e ) / u s r / l o c a l / b i n / v i r t u o s o - t + c o n f i g f i l e / u s r / l o c a l / v a r / l i b / v i r t u o s o / d b / v i r t u o s o . i n i ' I also added boto3 to hello_world/requirements.txt.
b o t o 3
Local testing can be done with the following. If using a profile other than the default, provide the appropriate profile name for xxxx.
s a m b u i l d & & s a m l o c a l i n v o k e - p r o f i l e x x x x AWS SAM: Updating template.yaml# Modify template.yaml so that the Lambda function is executed in response to SNS notifications.
A T D # G R O W r e l e u S a s c S M o F s V t V V T n c j a o b u o i p i i e s r - m r a n T M u r T P u r D V r D V m f i v p e l c i e r t y r t t e a t e a p o p i l s t m m c u p o C H R A # # E s u s l u s l l r t r e i : i e o e o e p o a u r v : o c u o c u a m i t n o o r s s : e d n n c - T r e M s r e s r e t : o u S f n u y : o r e d t h h e n y o i : o i : e n o A o : t S R A t U l i i x i c t S T P R p R p F A : s M : i e W i r e m t 8 s e s N y r e t ! e t ! o W o a z s S e i r e e 6 i : S p o T s i G s i G r S > - T b 1 e t : s : : : c _ p v T e p o t o e t o e m : r e o 5 : a : : t 6 r e r : e p a n t a n t a : e m u r S v a p u 4 o s i r i r : A r : A t S s p t 1 t e i p y r p g S t c t t t t V e t l 2 e r r p t e e a g N i : e " t e " t e r a a G 8 r v t . h s r e S e r V r I r v r t l : e u l o : t m r s a : i V I m V s e t e o r o a n y e : : r r i a p i i r b l s m 3 s n t r m l r o l f a e o b . a s : u t R i t n e o l s _ d 9 s a a o u o c u : s r s s r a s g w s o l i o s : : e _ o e s o s e t s ' - r : s h c , : o : o 2 2 e h F t a i s R R I R 0 0 s t u a n a t n e e A e 1 1 t t n r d t h s s s M s 0 6 a p c t l e e : t t t - - r s t / e s u a a R a 0 1 t : i r L s r r o r 9 0 i / o t a - t t l t - - n / n h m e e e e e 0 3 g g i b a r r r 9 1 i # s d s . c R ' V t a t L A r o i h M L - a r e l r u o a f 1 m n a e t b r m u : b t . u . e b n x d e A o c d c x a d r s o i a t x n o m n i x F f / f f o x u o i a o u n : n r n w n x c s s a c i x t V t l b t s x i i a a o i x o r n b u o i x n t c s t n n u e / v A o s s F w o # R s e u i k N o r n t e A " v c h d R R e t N e r i t s l o h o t e n e f a s r s R S t t - e N h e a s S e r p o p u t e f l r o x u i c p i n c e i s c a : c t t t i i i h d n o o t e g n n t f " - p i S m s n N o : e S d / d e / t l g a o / i b p b t o i l h v c o u e b b , / . m c s a o o s m t / t e a h r w a / s t d l o a w c b h s s e / / n g s e l e v o r e b v r a e l r t s l h . e e r s s s t t - o a p p i p c l i c a t i o n - m o d e l / b l o b / m a s t e r / v e r s i o n s / 2 0 1 6 - 1 0 - 3 1 . m d # a w s s e r v e r l e s s f u n c t i o n
Please modify the “ARN of the existing SNS topic” to the appropriate value. Also, the folder name storing the Lambda function shown earlier has been changed from hello_world to virtuoso_restart.
AWS SAM: Deployment# Deployment is done with the following:
s a m b u i l d & & s a m d e p l o y - p r o f i l e x x x x Summary# Since this was my first time using SSM (AWS Systems Manager), it took some time to resolve the errors, but I found it to be a convenient feature.
I hope this serves as a useful reference for others.