@@ -69,7 +69,17 @@ class SnsNotifier extends Emitter {
69
69
subscriptionRequestId : this . subscriptionRequestId
70
70
} , 'response from SNS SubscribeURL' ) ;
71
71
const data = await this . describeInstance ( ) ;
72
- this . lifecycleState = data . AutoScalingGroups [ 0 ] . Instances [ 0 ] . LifecycleState ;
72
+
73
+ const group = data . AutoScalingGroups . find ( ( group ) =>
74
+ group . Instances && group . Instances . some ( ( instance ) => instance . InstanceId === this . instanceId )
75
+ ) ;
76
+ if ( ! group ) {
77
+ this . logger . error ( 'Current instance not found in any Auto Scaling group' , data ) ;
78
+ } else {
79
+ const instance = group . Instances . find ( ( instance ) => instance . InstanceId === this . instanceId ) ;
80
+ this . lifecycleState = instance . LifecycleState ;
81
+ }
82
+
73
83
this . emit ( 'SubscriptionConfirmation' , { publicIp : this . publicIp } ) ;
74
84
break ;
75
85
@@ -137,13 +147,13 @@ class SnsNotifier extends Emitter {
137
147
try {
138
148
const params = {
139
149
Protocol : 'http' ,
140
- TopicArn : process . env . AWS_SNS_TOPIC_ARM ,
150
+ TopicArn : process . env . AWS_SNS_TOPIC_ARN ,
141
151
Endpoint : this . snsEndpoint
142
152
} ;
143
153
const response = await snsClient . send ( new SubscribeCommand ( params ) ) ;
144
- this . logger . info ( { response} , `response to SNS subscribe to ${ process . env . AWS_SNS_TOPIC_ARM } ` ) ;
154
+ this . logger . info ( { response} , `response to SNS subscribe to ${ process . env . AWS_SNS_TOPIC_ARN } ` ) ;
145
155
} catch ( err ) {
146
- this . logger . error ( { err} , `Error subscribing to SNS topic arn ${ process . env . AWS_SNS_TOPIC_ARM } ` ) ;
156
+ this . logger . error ( { err} , `Error subscribing to SNS topic arn ${ process . env . AWS_SNS_TOPIC_ARN } ` ) ;
147
157
}
148
158
}
149
159
@@ -154,9 +164,9 @@ class SnsNotifier extends Emitter {
154
164
SubscriptionArn : this . subscriptionArn
155
165
} ;
156
166
const response = await snsClient . send ( new UnsubscribeCommand ( params ) ) ;
157
- this . logger . info ( { response} , `response to SNS unsubscribe to ${ process . env . AWS_SNS_TOPIC_ARM } ` ) ;
167
+ this . logger . info ( { response} , `response to SNS unsubscribe to ${ process . env . AWS_SNS_TOPIC_ARN } ` ) ;
158
168
} catch ( err ) {
159
- this . logger . error ( { err} , `Error unsubscribing to SNS topic arn ${ process . env . AWS_SNS_TOPIC_ARM } ` ) ;
169
+ this . logger . error ( { err} , `Error unsubscribing to SNS topic arn ${ process . env . AWS_SNS_TOPIC_ARN } ` ) ;
160
170
}
161
171
}
162
172
0 commit comments